AceTime
0.1
Date and time classes for Arduino that supports the TZ DAtabase, and a system clock synchronized from an NTP server or an RTC chip.
|
A thin wrapper that represents a time offset from a reference point, usually 00:00 at UTC, but not always. More...
#include <TimeOffset.h>
Public Member Functions | |
TimeOffset () | |
Constructor. More... | |
bool | isZero () const |
Returns true if offset is 00:00. More... | |
int8_t | toOffsetCode () const |
Return the time offset as the number of 15 minute increments. More... | |
int16_t | toMinutes () const |
Return the time offset as minutes. More... | |
int32_t | toSeconds () const |
Return the time offset as seconds. More... | |
void | toHourMinute (int8_t &hour, uint8_t &minute) const |
Extract hour and minute representation of the offset. More... | |
bool | isError () const |
Return true if this TimeOffset represents an error. More... | |
void | printTo (Print &printer) const |
Print the human readable string. More... | |
TimeOffset (const TimeOffset &)=default | |
TimeOffset & | operator= (const TimeOffset &)=default |
Static Public Member Functions | |
static TimeOffset | forHour (int8_t hour) |
Create TimeOffset with the corresponding hour offset. More... | |
static TimeOffset | forHourMinute (int8_t hour, uint8_t minute) |
Create TimeOffset from (hour, minute) offset, where the sign of hour determines the sign of the offset. More... | |
static TimeOffset | forMinutes (int16_t minutes) |
Create TimeOffset from minutes from 00:00. More... | |
static TimeOffset | forOffsetString (const char *offsetString) |
Create from an offset string ("-07:00" or "+01:00"). More... | |
static TimeOffset | forError () |
Return an error indicator. More... | |
static TimeOffset | forOffsetCode (int8_t offsetCode) |
Create TimeOffset from the offset code. More... | |
Friends | |
class | BasicZoneSpecifier |
class | ManualZoneSpecifier |
class | TimeZone |
class | OffsetDateTime |
class | TimeOffsetMutator |
bool | operator== (const TimeOffset &a, const TimeOffset &b) |
void | time_offset_mutation::incrementHour (TimeOffset &offset) |
void | time_offset_mutation::increment15Minutes (TimeOffset &offset) |
A thin wrapper that represents a time offset from a reference point, usually 00:00 at UTC, but not always.
Use one of the static factory methods to create an instance. For example, each of the following creates a TimeOffset of -08:00:
You can use the default constructor to create a +00:00 TimeOffset:
According to https://en.wikipedia.org/wiki/List_of_UTC_time_offsets, all time zones currently in use occur at 15 minute boundaries, and the smallest time zone is UTC-12:00 and the biggest time zone is UTC+14:00. Therefore, we can encode all currently used time zones as integer multiples of 15-minute offsets from UTC. This allows the TimeOffset to be stored as a single 8-bit signed integer. For the most part, the internal implementation of this class does not leak out to the outside world, so it should be relatively easy to change its implementation to a 16-bit integer to support 1-minute granularity instead of 15-minute granularity.
This class does NOT know about the "tz database" (aka Olson database) https://en.wikipedia.org/wiki/Tz_database. That functionality is implemented in the TimeZone class.
Definition at line 53 of file TimeOffset.h.
|
inlineexplicit |
Constructor.
Create a time zone corresponding to UTC with no offset.
Definition at line 102 of file TimeOffset.h.
|
inlinestatic |
Return an error indicator.
Definition at line 90 of file TimeOffset.h.
|
inlinestatic |
Create TimeOffset with the corresponding hour offset.
For example, -08:00 is 'forHour(-8)'.
Definition at line 59 of file TimeOffset.h.
|
inlinestatic |
Create TimeOffset from (hour, minute) offset, where the sign of hour determines the sign of the offset.
The 'minute' must be in multiples of 15-minutes and is always positive. For example, -07:30 is 'forHourMinute(-7, 30)'.
Definition at line 69 of file TimeOffset.h.
|
inlinestatic |
Create TimeOffset from minutes from 00:00.
In the current implementation, the minutes is truncated to the 15-minute boundary towards 0.
Definition at line 79 of file TimeOffset.h.
|
inlinestatic |
Create TimeOffset from the offset code.
offsetCode | the amount of time offset in 15-minute increments. |
Definition at line 97 of file TimeOffset.h.
|
static |
Create from an offset string ("-07:00" or "+01:00").
Intended mostly for testing purposes.
Definition at line 24 of file TimeOffset.cpp.
|
inline |
Return true if this TimeOffset represents an error.
Definition at line 133 of file TimeOffset.h.
|
inline |
Returns true if offset is 00:00.
If this represents a time zone, then isZero means that it is UTC. If this represents a DST delta offset, then isZero means that the time zone is in standard time.
Definition at line 109 of file TimeOffset.h.
void ace_time::TimeOffset::printTo | ( | Print & | printer | ) | const |
Print the human readable string.
For example, "-08:00".
Definition at line 10 of file TimeOffset.cpp.
|
inline |
Extract hour and minute representation of the offset.
Definition at line 125 of file TimeOffset.h.
|
inline |
Return the time offset as minutes.
Definition at line 115 of file TimeOffset.h.
|
inline |
Return the time offset as the number of 15 minute increments.
Definition at line 112 of file TimeOffset.h.
|
inline |
Return the time offset as seconds.
Definition at line 120 of file TimeOffset.h.