AceTime
1.1
Date and time classes for Arduino that support timezones from the TZ Database, and a system clock that can synchronize 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 | forTimeStringChainable (const char *&timeString) |
Variant of forTimeString() that updates the pointer to the next unprocessed character. 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 | |
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 11 (https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/time/LocalTime.html).
Definition at line 26 of file LocalTime.h.
|
inlineexplicit |
Default constructor does nothing.
Definition at line 98 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 151 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 41 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 93 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 54 of file LocalTime.h.
|
static |
Factory method.
Create a LocalTime from the ISO 8601 time string. If the string cannot be parsed, then returns LocalTime::forError(). However, the data validation on parsing is very weak and the behavior is undefined for most invalid time strings.
Definition at line 27 of file LocalTime.cpp.
|
static |
Variant of forTimeString() that updates the pointer to the next unprocessed character.
This allows chaining to another forXxxStringChainable() method.
This method assumes that the dateString is sufficiently long.
Definition at line 35 of file LocalTime.cpp.
|
inline |
Return the hour.
Definition at line 116 of file LocalTime.h.
|
inline |
Set the hour.
Definition at line 119 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 106 of file LocalTime.h.
|
inline |
Return the minute.
Definition at line 122 of file LocalTime.h.
|
inline |
Set the minute.
Definition at line 125 of file LocalTime.h.
void ace_time::LocalTime::printTo | ( | Print & | printer | ) | const |
Print LocalTime to 'printer' in ISO 8601 format.
This class does not implement the Printable interface to avoid increasing the size of the object from the additional virtual function.
Definition at line 13 of file LocalTime.cpp.
|
inline |
Return the second.
Definition at line 128 of file LocalTime.h.
|
inline |
Set the second.
Definition at line 131 of file LocalTime.h.
|
inline |
Return the number of seconds since midnight.
Return kInvalidSeconds if isError() is true.
Definition at line 137 of file LocalTime.h.
Return true if two LocalTime objects are equal.
Definition at line 193 of file LocalTime.h.
|
static |
An invalid seconds marker that indicates isError() true.
Definition at line 29 of file LocalTime.h.