Global time settings.
More...
#include <LocalTimeRK.h>
|
static LocalTime & | instance () |
| Get the global singleton instance of this class.
|
|
static void | timeToTm (time_t time, struct tm *pTimeInfo) |
| Converts a Unix time (seconds past Jan 1 1970) UTC value to a struct tm. More...
|
|
static time_t | tmToTime (struct tm *pTimeInfo) |
| Converts a struct tm to a Unix time (seconds past Jan 1 1970) UTC. More...
|
|
static String | getTmString (struct tm *pTimeInfo) |
| Returns a human-readable string version of a struct tm. More...
|
|
static time_t | stringToTime (const char *str, struct tm *pTimeInfo=NULL) |
| Converts a string in ISO-8601 format (ignoring the timezone) More...
|
|
static String | timeToString (time_t time, char separator=' ') |
| Converts a time to a string in a modified ISO-8601 format with no timezone. More...
|
|
static int | lastDayOfMonth (int year, int month) |
| Returns the last day of the month in a given month and year. More...
|
|
static int | dayOfWeekOfMonth (int year, int month, int dayOfWeek, int ordinal) |
| Return the nth instance of a day of week in a month and year. More...
|
|
|
| LocalTime () |
| This class is a singleton and should not be manually allocated.
|
|
virtual | ~LocalTime () |
| This class is a singleton and should not be manually destructed.
|
|
| LocalTime (const LocalTime &)=delete |
| This class is not copyable.
|
|
LocalTime & | operator= (const LocalTime &)=delete |
| This class is not copyable.
|
|
|
LocalTimePosixTimezone | config |
| Global default timezone. More...
|
|
int | scheduleLookaheadDays = 100 |
| Number of days to look forward to see if there are scheduled events. Default: 100.
|
|
|
static LocalTime * | _instance |
| Singleton instance of this class.
|
|
◆ dayOfWeekOfMonth()
int LocalTime::dayOfWeekOfMonth |
( |
int |
year, |
|
|
int |
month, |
|
|
int |
dayOfWeek, |
|
|
int |
ordinal |
|
) |
| |
|
static |
Return the nth instance of a day of week in a month and year.
- Parameters
-
year | The 4-digit year (2020, for example) |
month | Month 1 - 12 inclusive, 1 = January, 12 = December |
dayOfWeek | 0 = Sunday, 1 = Monday, 2 = Tuesday, ..., 6 = Saturday |
ordinal | 1 = first instance of that day of week in the month, 2 = second, ... |
- Returns
- int The day of the month, or 0 if that ordinal does not exist in the month
◆ getScheduleLookaheadDays()
int LocalTime::getScheduleLookaheadDays |
( |
| ) |
const |
|
inline |
Gets the maximum number of days to look ahead in the schedule for a match.
- Returns
- int
◆ getTmString()
String LocalTime::getTmString |
( |
struct tm * |
pTimeInfo | ) |
|
|
static |
Returns a human-readable string version of a struct tm.
- Parameters
-
pTimeInfo | Pointer to a struct tm to convert |
◆ lastDayOfMonth()
int LocalTime::lastDayOfMonth |
( |
int |
year, |
|
|
int |
month |
|
) |
| |
|
static |
Returns the last day of the month in a given month and year.
- Parameters
-
year | The year (note, actual year like 2021, not the value of tm_year). |
month | The month (1 - 12) |
For example, If the month in the current object is January, returns 31. The year is required to handle leap years when the month is February.
◆ stringToTime()
time_t LocalTime::stringToTime |
( |
const char * |
str, |
|
|
struct tm * |
pTimeInfo = NULL |
|
) |
| |
|
static |
Converts a string in ISO-8601 format (ignoring the timezone)
- Parameters
-
str | String to convert |
pTimeInfo | Pointer to a struct tm to fill in or NULL if you don't need that |
- Returns
- a time_t (Unix time, seconds past January 1, 1970, UTC)
The string must be of the form "YYYY-MM-DDTHH:MM:SS". Any additional characters are ignored, so it's OK if the time includes the timezone, though it will be ignored. Same for milliseconds. The T between the day and hour can be any single non-numeric character, such as a space, instead of a T.
See also timeToString to convert in the other direction.
◆ timeToString()
String LocalTime::timeToString |
( |
time_t |
time, |
|
|
char |
separator = ' ' |
|
) |
| |
|
static |
Converts a time to a string in a modified ISO-8601 format with no timezone.
- Parameters
-
time | Unix time (seconds past Jan 1 1970) UTC |
separator | the separator between the day of month and hour, typically T or a space. |
- Returns
- a time_t (Unix time, seconds past January 1, 1970, UTC)
The string will be of the form "YYYY-MM-DDTHH:MM:SS".
See also timeToString to convert in the other direction.
◆ timeToTm()
void LocalTime::timeToTm |
( |
time_t |
time, |
|
|
struct tm * |
pTimeInfo |
|
) |
| |
|
static |
Converts a Unix time (seconds past Jan 1 1970) UTC value to a struct tm.
- Parameters
-
time | Unix time (seconds past Jan 1 1970) UTC |
pTimeInfo | Pointer to a struct tm that is filled in with the time broken out into components |
The struct tm contains the following members:
- tm_sec seconds (0-59). Could in theory be up to 61 with leap seconds, but never is
- tm_min minute (0-59)
- tm_hour hour (0-23)
- tm_mday day of month (1-31)
- tm_mon month (0-11). This is 0-11 not 1-12! Beware!
- tm_year year since 1900. Note: 2021 is 121, not 2021 or 21! Beware!
- tm_wday Day of week (Sunday = 0, Monday = 1, Tuesday = 2, ..., Saturday = 6)
- tm_yday Day of year (0 - 365). Note: zero-based, January 1 = 0
- tm_isdst Daylight saving flag, always 0 on Particle devices
This basically a wrapper around localtime_r or gmtime_r.
◆ tmToTime()
time_t LocalTime::tmToTime |
( |
struct tm * |
pTimeInfo | ) |
|
|
static |
Converts a struct tm to a Unix time (seconds past Jan 1 1970) UTC.
- Parameters
-
pTimeInfo | Pointer to a struct tm |
Note: tm_wday, tm_yday, and tm_isdst are ignored for calculating the result, however tm_wday and tm_yday are filled in with the correct values based on the date, which is why pTimeInfo is not const.
This basically a wrapper around mktime or timegm.
◆ withScheduleLookaheadDays()
LocalTime & LocalTime::withScheduleLookaheadDays |
( |
int |
value | ) |
|
|
inline |
Sets the maximum number of days to look ahead in the schedule for a match (default: 3)
- Parameters
-
- Returns
- LocalTime&
◆ config
Global default timezone.
The LocalTimeConverter class will use this if a config is not set for that specific converter.
The documentation for this class was generated from the following files: