Timezone Class Reference

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

#include <Timezone.h>

Public Member Functions

 Timezone ()
 
 Timezone (const TimeChangeRule &dstStart, const TimeChangeRule &stdStart)
 
void init (const TimeChangeRule &dstStart, const TimeChangeRule &stdStart)
 
time_t toLocal (time_t utc, const TimeChangeRule **p_tcr=nullptr)
 Convert the given UTC time to local time, standard or daylight time. More...
 
time_t 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...
 

Detailed Description

Class to support local/UTC time conversions using rules.

Constructor & Destructor Documentation

◆ Timezone() [1/2]

Timezone::Timezone ( )
inline

◆ Timezone() [2/2]

Timezone::Timezone ( const TimeChangeRule dstStart,
const TimeChangeRule stdStart 
)
inline

Member Function Documentation

◆ init()

void Timezone::init ( const TimeChangeRule dstStart,
const TimeChangeRule stdStart 
)

◆ localTimeTag()

const char* 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 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

◆ timeTag()

const char* 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 Timezone::toLocal ( time_t  utc,
const TimeChangeRule **  p_tcr = nullptr 
)

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

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

◆ toUTC()

time_t Timezone::toUTC ( time_t  local)

Convert the given local time to UTC time.

Parameters
localLocal time
Return values
time_tTime in UTC
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 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* 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: