|
LocalTimeRK
|
Container for a local time value with accessors similar to the Wiring Time class. More...
#include <LocalTimeRK.h>
Public Member Functions | |
| int | hour () const |
| Returns the hour (0 - 23) | |
| int | hourFormat12 () const |
| Returns the hour (1 - 12) used in AM/PM mode. | |
| uint8_t | isAM () const |
| Returns true if the time is in the AM (before noon) | |
| uint8_t | isPM () const |
| Returns true if the time is in the PM (>= 12:00:00 in 24-hour clock). | |
| int | minute () const |
| Returns the minute 0 - 59. | |
| int | second () const |
| Returns the second 0 - 59. | |
| int | day () const |
| Returns the day of the month 1 - 31 (or less in some months) | |
| int | weekday () const |
| Returns the day of week 1 - 7 (Sunday = 1, Monday = 2, ..., Saturday = 7) More... | |
| int | month () const |
| Returns the month of the year 1 - 12 (1 = January, 2 = February, ...) More... | |
| int | year () const |
| Returns the 4-digit year. | |
| LocalTimeHMS | hms () const |
| Gets the local time as a LocalTimeHMS object. | |
| void | setHMS (LocalTimeHMS hms) |
| Sets the local time from a LocalTimeHMS object. | |
| LocalTimeYMD | ymd () const |
| Get the date portion of this object as a LocalTimeYMD. More... | |
| time_t | toUTC (LocalTimePosixTimezone config) const |
| Converts the specified local time into a UTC time. More... | |
| void | fromString (const char *str) |
| Converts time from ISO-8601 format, ignoring the timezone. More... | |
| int | ordinal () const |
| Returns which week of this day it is. More... | |
Container for a local time value with accessors similar to the Wiring Time class.
Really just a C++ wrapper around struct tm with adjustments for weekday and month being 0-based in struct tm and 1-based in Wiring. Also tm_year being weird in struct tm.
If you want to format a time string, use the methods in LocalTimeConvert. The reason is that the LocalTimeValue is only the value container and doesn't know the current timezone offset for the local time.
| void LocalTimeValue::fromString | ( | const char * | str | ) |
Converts time from ISO-8601 format, ignoring the timezone.
| str | The string to convert |
The string should be of the form:
YYYY-MM-DDTHH:MM:SS
The T can be any single character, such as a space. For example:
2021-04-01 10:00:00
Any characters after the seconds are ignored.
|
inline |
Returns the month of the year 1 - 12 (1 = January, 2 = February, ...)
Note: the underlying struct tm tm_mon is 0 - 11, but this returns the more common 1 - 12.
| int LocalTimeValue::ordinal | ( | ) | const |
Returns which week of this day it is.
For example, if this day is a Friday and it's the first Friday of the month, then 1 is returned. If it's the second Friday, then 2 is returned.
(This is different than the week number of the month, which depends on which day you begin the week on.)
| time_t LocalTimeValue::toUTC | ( | LocalTimePosixTimezone | config | ) | const |
Converts the specified local time into a UTC time.
There are some caveats to this that occur on when the time change occurs. On spring forward, there is an hour that doesn't technically map to a UTC time. For example, in the United States, 2:00 AM to 3:00 AM local time doesn't exist because at 2:00 AM local time, the local time springs forward to 3:00 AM.
When falling back, the hour from 1:00 AM to 2:00 AM is not unique, because it happens twice, once in DST before falling back, and a second time after falling back. The toUTC() function returns the second one that occurs in standard time.
|
inline |
Returns the day of week 1 - 7 (Sunday = 1, Monday = 2, ..., Saturday = 7)
Note: the underlying struct tm tm_wday is 0 - 6 (Sunday = 0, Monday = 1, ..., Saturday = 6) but Wiring uses 1 - 7 instead of 0 - 6.
| LocalTimeYMD LocalTimeValue::ymd | ( | ) | const |
Get the date portion of this object as a LocalTimeYMD.