TZ::Timezone Class Reference

Class to support local/UTC time conversions using rules. More...

#include <Timezone.h>

Public Member Functions

 Timezone ()
 
 Timezone (const Rule &dstStart, const Rule &stdStart)
 Create a timezone with daylight savings. More...
 
 Timezone (const Rule &std)
 Create a timezone which has no daylight savings. More...
 
void init (const Rule &dstStart, const Rule &stdStart)
 
 operator bool () const
 
time_t toLocal (time_t utc, const Rule **rule=nullptr)
 Convert the given UTC time to local time, standard or daylight time. More...
 
ZonedTime makeZoned (time_t utc, bool beforeTransition=false)
 Obtain a ZonedTime instance for the given UTC. More...
 
ZonedTime toUTC (time_t local)
 Convert the given local time to UTC time. More...
 
bool utcIsDST (time_t utc)
 Determine whether the UTC time is within the DST interval or the Standard time interval. More...
 
bool locIsDST (time_t local)
 Determine whether the given local time is within the DST interval or the Standard time interval. More...
 
const char * timeTag (bool isDst) const
 Return the appropriate dalight-savings tag to append to displayed times. More...
 
const char * utcTimeTag (time_t utc)
 Return the appropriate time tag for a UTC time. More...
 
const char * localTimeTag (time_t local)
 Return the appropriate time tag for a local time. More...
 
ZonedTime getNextChange (time_t utcFrom)
 Determine when the next change to/from DST is. More...
 
ZonedTime getTransition (uint16_t year, bool toDst)
 Get transition time for the given year. More...
 
const RulegetRule (bool isDst) const
 Get reference to a timechange rule. More...
 
bool hasDaylightSavings () const
 If dst and std rules are the same we do not use daylight savings. More...
 
String toString () const
 
size_t printTo (Print &p) const
 

Static Public Member Functions

Construct a Timezone from a POSIX rule string
static Timezone fromPosix (const char *tzstr)
 
static Timezone fromPosix (const String &tzstr)
 

Detailed Description

Class to support local/UTC time conversions using rules.

Constructor & Destructor Documentation

◆ Timezone() [1/3]

TZ::Timezone::Timezone ( )
inline

◆ Timezone() [2/3]

TZ::Timezone::Timezone ( const Rule dstStart,
const Rule stdStart 
)
inline

Create a timezone with daylight savings.

Parameters
dstStartRule giving start of daylight savings
stdStartRule giving start of standard time
Note
If both rules are the same then the zone operates in permanent standard time

◆ Timezone() [3/3]

TZ::Timezone::Timezone ( const Rule std)
inlineexplicit

Create a timezone which has no daylight savings.

Parameters
stdRule describing standard time
Note
Only tag and offset fields from rule are significant

Member Function Documentation

◆ fromPosix() [1/2]

static Timezone TZ::Timezone::fromPosix ( const char *  tzstr)
static

◆ fromPosix() [2/2]

static Timezone TZ::Timezone::fromPosix ( const String tzstr)
inlinestatic

◆ getNextChange()

ZonedTime TZ::Timezone::getNextChange ( time_t  utcFrom)

Determine when the next change to/from DST is.

Parameters
utcFromPoint in time after which change is to occur
Return values
ZonedTimeUTC time When the change will occur, or maxTime if there is no DST in effect. ZonedTime::local() returns the new local time at the transition.

◆ getRule()

const Rule& TZ::Timezone::getRule ( bool  isDst) const
inline

Get reference to a timechange rule.

Parameters
isDsttrue for DST rule, false for STD rule
Return values
Rule

◆ getTransition()

ZonedTime TZ::Timezone::getTransition ( uint16_t  year,
bool  toDst 
)

Get transition time for the given year.

Parameters
year
toDsttrue to obtain STD->DST transition, false for DST->STD
Return values
ZonedTimeTime of transition, or maxTime if there is no DST in effect. ZonedTime::local() returns the new local time at the transition.

◆ hasDaylightSavings()

bool TZ::Timezone::hasDaylightSavings ( ) const
inline

If dst and std rules are the same we do not use daylight savings.

◆ init()

void TZ::Timezone::init ( const Rule dstStart,
const Rule stdStart 
)
inline

@deprected Use copy assignment, e.g. tz = Timezone(...)

◆ localTimeTag()

const char* TZ::Timezone::localTimeTag ( time_t  local)
inline

Return the appropriate time tag for a local time.

Parameters
localThe local time
Return values
constchar* Tag, such as UTC, BST, etc.

◆ locIsDST()

bool TZ::Timezone::locIsDST ( time_t  local)

Determine whether the given local time is within the DST interval or the Standard time interval.

Parameters
localLocal time
Return values
booltrue if time is within DST

◆ makeZoned()

ZonedTime TZ::Timezone::makeZoned ( time_t  utc,
bool  beforeTransition = false 
)

Obtain a ZonedTime instance for the given UTC.

Parameters
utcTime in UTC
beforeTransitionIf time is exactly on a transition to/from daylight savings then this determines whether the returned information contains the local time prior to the change or after the change.
Return values
ZonedTimeContains the UTC time given plus offset, etc. at that point in time

◆ operator bool()

TZ::Timezone::operator bool ( ) const
inlineexplicit

◆ printTo()

size_t TZ::Timezone::printTo ( Print p) const

◆ timeTag()

const char* TZ::Timezone::timeTag ( bool  isDst) const
inline

Return the appropriate dalight-savings tag to append to displayed times.

Parameters
isDsttrue if DST tag is required, otherwise non-DST tag is returned
Return values
constchar* The tag

◆ toLocal()

time_t TZ::Timezone::toLocal ( time_t  utc,
const Rule **  rule = nullptr 
)

Convert the given UTC time to local time, standard or daylight time.

Parameters
utcTime in UTC
ruleOptionally return the rule used to convert the time
Return values
time_tThe local time

◆ toString()

String TZ::Timezone::toString ( ) const

◆ toUTC()

ZonedTime TZ::Timezone::toUTC ( time_t  local)

Convert the given local time to UTC time.

Parameters
localLocal time
Return values
ZonedTimeContains UTC point in time with associated local offset, etc.
Note

WARNING: This function is provided for completeness, but should seldom be needed and should be used sparingly and carefully.

Ambiguous situations occur after the Standard-to-DST and the DST-to-Standard time transitions. When changing to DST, there is one hour of local time that does not exist, since the clock moves forward one hour. Similarly, when changing to standard time, there is one hour of local times that occur twice since the clock moves back one hour.

This function does not test whether it is passed an erroneous time value during the Local -> DST transition that does not exist. If passed such a time, an incorrect UTC time value will be returned.

If passed a local time value during the DST -> Local transition that occurs twice, it will be treated as the earlier time, i.e. the time that occurs before the transition.

Calling this function with local times during a transition interval should be avoided.

◆ utcIsDST()

bool TZ::Timezone::utcIsDST ( time_t  utc)

Determine whether the UTC time is within the DST interval or the Standard time interval.

Parameters
utc
Return values
booltrue if time is within DST

◆ utcTimeTag()

const char* TZ::Timezone::utcTimeTag ( time_t  utc)
inline

Return the appropriate time tag for a UTC time.

Parameters
utcThe time in UTC
Return values
constchar* Tag, such as UTC, BST, etc.

The documentation for this class was generated from the following file: