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.
|
The time (hour, minute, second) fields representing the time without regards to the day or the time zone. More...
#include <LocalTime.h>
Public Member Functions | |
LocalTime () | |
Default constructor does nothing. More... | |
bool | isError () const |
Return true if any component is outside the normal time range of 00:00:00 to 23:59:59. More... | |
uint8_t | hour () const |
Return the hour. More... | |
void | hour (uint8_t hour) |
Set the hour. More... | |
uint8_t | minute () const |
Return the minute. More... | |
void | minute (uint8_t month) |
Set the minute. More... | |
uint8_t | second () const |
Return the second. More... | |
void | second (uint8_t second) |
Set the second. More... | |
acetime_t | toSeconds () const |
Return the number of seconds since midnight. More... | |
int8_t | compareTo (const LocalTime &that) const |
Compare this LocalTime with that LocalTime, and return (<0, 0, >0) according to whether (this<that, this==that, this>that). More... | |
void | printTo (Print &printer) const |
Print LocalTime to 'printer' in ISO 8601 format. More... | |
LocalTime (const LocalTime &)=default | |
LocalTime & | operator= (const LocalTime &)=default |
Static Public Member Functions | |
static LocalTime | forComponents (uint8_t hour, uint8_t minute, uint8_t second) |
Factory method using separated date, time, and time zone fields. More... | |
static LocalTime | forSeconds (acetime_t seconds) |
Factory method. More... | |
static LocalTime | forTimeString (const char *timeString) |
Factory method. More... | |
static LocalTime | forError () |
Factory method that returns an instance which indicates an error condition. More... | |
Static Public Attributes | |
static const acetime_t | kInvalidSeconds = INT32_MIN |
An invalid seconds marker that indicates isError() true. More... | |
Friends | |
class | LocalDateTime |
class | OffsetDateTime |
bool | operator== (const LocalTime &a, const LocalTime &b) |
Return true if two LocalTime objects are equal. More... | |
The time (hour, minute, second) fields representing the time without regards to the day or the time zone.
The valid range is 00:00:00 to 23:59:59. Trying to create an instance outside of this range causes the isError() method to return true, and toSeconds() returns kInvalidSeconds.
Parts of this class were inspired by the java.time.LocalTime class of Java 8 (https://docs.oracle.com/javase/8/docs/api/java/time/LocalTime.html).
Definition at line 20 of file LocalTime.h.
|
inlineexplicit |
Default constructor does nothing.
Definition at line 81 of file LocalTime.h.
|
inline |
Compare this LocalTime with that LocalTime, and return (<0, 0, >0) according to whether (this<that, this==that, this>that).
The behavior is undefined if isError() is true.
Definition at line 134 of file LocalTime.h.
|
inlinestatic |
Factory method using separated date, time, and time zone fields.
The dayOfWeek will be lazily evaluated. No data validation is performed on the fields on construction, but if any field is out of range, then isError() will return true.
hour | hour (0-23) |
minute | minute (0-59) |
second | second (0-59), does not support leap seconds |
Definition at line 35 of file LocalTime.h.
|
inlinestatic |
Factory method that returns an instance which indicates an error condition.
The isError() method will return true.
Definition at line 76 of file LocalTime.h.
|
inlinestatic |
Factory method.
Create the various components of the LocalTime from the number of seconds from midnight. If kInvalidSeconds is given, the isError() condition is set to be true. The behavior is undefined if seconds is greater than 86399.
seconds | number of seconds from midnight, (0-86399) |
Definition at line 48 of file LocalTime.h.
|
static |
Factory method.
Create a LocalTime from the ISO 8601 time string. If the string cannot be parsed, then isError() on the constructed object returns true. However, the data validation on parsing is very weak and the behavior is undefined for most invalid time strings.
Definition at line 22 of file LocalTime.cpp.
|
inline |
Return the hour.
Definition at line 99 of file LocalTime.h.
|
inline |
Set the hour.
Definition at line 102 of file LocalTime.h.
|
inline |
Return true if any component is outside the normal time range of 00:00:00 to 23:59:59.
We add the exception that 24:00:00 is also considered valid to allow AutoZoneSpecififier to support midnight transitions from the TZ Database.
Definition at line 89 of file LocalTime.h.
|
inline |
Return the minute.
Definition at line 105 of file LocalTime.h.
|
inline |
Set the minute.
Definition at line 108 of file LocalTime.h.
void ace_time::LocalTime::printTo | ( | Print & | printer | ) | const |
Print LocalTime to 'printer' in ISO 8601 format.
Does not implement Printable to avoid memory cost of a vtable pointer.
Definition at line 8 of file LocalTime.cpp.
|
inline |
Return the second.
Definition at line 111 of file LocalTime.h.
|
inline |
Set the second.
Definition at line 114 of file LocalTime.h.
|
inline |
Return the number of seconds since midnight.
Return kInvalidSeconds if isError() is true.
Definition at line 120 of file LocalTime.h.
Return true if two LocalTime objects are equal.
Definition at line 185 of file LocalTime.h.
|
static |
An invalid seconds marker that indicates isError() true.
Definition at line 23 of file LocalTime.h.