#include <SystemClock.h>

Public Types

using CheckTimeZoneOffset = Delegate< void(time_t systemTime)>
 Optional callback which can be used to automate handling of timezone changes. More...
 

Public Member Functions

time_t now (TimeZone timeType=eTZ_Local) const
 Get the current date and time. More...
 
bool setTime (time_t time, TimeZone timeType)
 Set the system clock's time. More...
 
String getSystemTimeString (TimeZone timeType=eTZ_Local) const
 Get current time as a string. More...
 
void setTimeZoneOffset (int seconds)
 Sets the local time zone offset. More...
 
void setTimeZone (float localTimezoneOffset)
 Set the local time zone offset in hours. More...
 
void setTimeZone (const DateTime::ZoneInfo &zoneInfo)
 Set current time zone information. More...
 
const DateTime::ZoneInfogetTimeZone () const
 Get current time zone information. More...
 
int getTimeZoneOffset () const
 Get the current time zone offset. More...
 
bool isSet () const
 Determine if setTime() has been called yet. More...
 
void onCheckTimeZoneOffset (CheckTimeZoneOffset callback)
 Set/clear a callback which is invoked whenever local time is queried. More...
 

Member Typedef Documentation

◆ CheckTimeZoneOffset

using SystemClockClass::CheckTimeZoneOffset = Delegate<void(time_t systemTime)>

Optional callback which can be used to automate handling of timezone changes.

Parameters
systemTimeThe current system time

Although the timezone offset only changes twice a year, when it does change the corresponding offset should be updated promptly.

setTimeZoneOffset() is typically called when updating via real-time clock chip or NTP, but this can still leave a considerable gap during which the local time will be wrong.

The callback should check the provided systemTime and determine if the time zone offset requires changing and, if so, call setTimeZoneOffset(). One way to make this efficient is to cache the time_t value for the next change, rather than attemtpting to compute the offset on every call.

Member Function Documentation

◆ getSystemTimeString()

String SystemClockClass::getSystemTimeString ( TimeZone  timeType = eTZ_Local) const

Get current time as a string.

Parameters
timeTypeTime zone to present time as, i.e. return local or UTC time
Return values
StringCurrent time in format: dd.mm.yy hh:mm:ss

◆ getTimeZone()

const DateTime::ZoneInfo& SystemClockClass::getTimeZone ( ) const
inline

Get current time zone information.

Return values
ZoneInfo

◆ getTimeZoneOffset()

int SystemClockClass::getTimeZoneOffset ( ) const
inline

Get the current time zone offset.

Return values
intOffset in seconds from UTC

◆ isSet()

bool SystemClockClass::isSet ( ) const
inline

Determine if setTime() has been called yet.

Note
Indicates whether time returned can be relied upon

◆ now()

time_t SystemClockClass::now ( TimeZone  timeType = eTZ_Local) const

Get the current date and time.

Parameters
timeTypeTime zone to use (UTC / local)
Return values
DateTimeCurrent date and time

◆ onCheckTimeZoneOffset()

void SystemClockClass::onCheckTimeZoneOffset ( CheckTimeZoneOffset  callback)
inline

Set/clear a callback which is invoked whenever local time is queried.

Note
This callback is only invoked when now() is called.

◆ setTime()

bool SystemClockClass::setTime ( time_t  time,
TimeZone  timeType 
)

Set the system clock's time.

Parameters
timeUnix time to set clock to (quantity of seconds since 00:00:00 1970-01-01)
timeTypeTime zone of Unix time, i.e. is time provided as local or UTC?
Note
System time is always stored as UTC time. If setting using the value retrieved from a time server using NTP, specify eTZ_UTC. If passing a local value using eTZ_Local, ensure that the time zone has been set correctly as it will be converted to UTC before storing.

◆ setTimeZone() [1/2]

void SystemClockClass::setTimeZone ( const DateTime::ZoneInfo zoneInfo)
inline

Set current time zone information.

Parameters
zoneInfoContains offset plus string formatting information

◆ setTimeZone() [2/2]

void SystemClockClass::setTimeZone ( float  localTimezoneOffset)
inline

Set the local time zone offset in hours.

Parameters
localTimezoneOffsetOffset from UTC of local time zone in hours
Return values
booltrue on success, false if value out of range
Note
Values for local standard time may exceed +/- 12 For example, Pacific/Kiritimati has a 14-hour offset (in 2024).

◆ setTimeZoneOffset()

void SystemClockClass::setTimeZoneOffset ( int  seconds)
inline

Sets the local time zone offset.

Parameters
secondsOffset from UTC of local time zone in seconds
See also
See setTimeZone().

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