Sming Framework API
Sming - Open Source framework for high efficiency WiFi SoC ESP8266 native development with C++ language.
|
Date and time class. More...
#include <DateTime.h>
Public Member Functions | |
DateTime () | |
Instantiate an uninitialised date and time object. More... | |
DateTime (time_t time) | |
Instantiate a date and time object from a Unix timestamp. More... | |
operator time_t () | |
Get current Unix time. More... | |
void | setTime (time_t time) |
Set time using Unix timestamp. More... | |
void | setTime (uint8_t sec, uint8_t min, uint8_t hour, uint8_t day, uint8_t month, uint16_t year) |
Set time using time and date component values. More... | |
bool | fromHttpDate (const String &httpDate) |
Parse a HTTP full date and set time and date. More... | |
bool | parseHttpDate (const String &httpDate) SMING_DEPRECATED |
Parse a HTTP full date and set time and date. More... | |
bool | isNull () |
Check if time date object is initialised. More... | |
time_t | toUnixTime () |
Get Unix time. More... | |
String | toShortDateString () |
Get human readable date. More... | |
String | toShortTimeString (bool includeSeconds=false) |
Get human readable time. More... | |
String | toFullDateTimeString () |
Get human readable date and time. More... | |
String | toISO8601 () |
Get human readable date and time. More... | |
String | toHTTPDate () |
Get human readable date and time. More... | |
void | addMilliseconds (long add) |
Add time to date time object. More... | |
String | format (const char *formatString) |
Create string formatted with time and date placeholders. More... | |
String | format (const String &formatString) |
Create string formatted with time and date placeholders. More... | |
Static Public Member Functions | |
static void | fromUnixTime (time_t timep, uint8_t *psec, uint8_t *pmin, uint8_t *phour, uint8_t *pday, uint8_t *pwday, uint8_t *pmonth, uint16_t *pyear) |
Convert from Unix time to individual time components. More... | |
static void | fromUnixTime (time_t timep, int8_t *psec, int8_t *pmin, int8_t *phour, int8_t *pday, int8_t *pwday, int8_t *pmonth, int16_t *pyear) SMING_DEPRECATED |
static void | convertFromUnixTime (time_t timep, int8_t *psec, int8_t *pmin, int8_t *phour, int8_t *pday, int8_t *pwday, int8_t *pmonth, int16_t *pyear) SMING_DEPRECATED |
Convert from Unix time to individual time components. More... | |
static time_t | toUnixTime (uint8_t sec, uint8_t min, uint8_t hour, uint8_t day, uint8_t month, uint16_t year) |
Convert from individual time components to Unix time. More... | |
static time_t | convertToUnixTime (uint8_t sec, uint8_t min, uint8_t hour, uint8_t day, uint8_t month, uint16_t year) SMING_DEPRECATED |
Convert from individual time components to Unix time. More... | |
Public Attributes | |
uint8_t | Hour = 0 |
Hour (0-23) More... | |
uint8_t | Minute = 0 |
Minute (0-59) More... | |
uint8_t | Second = 0 |
Second (0-59) More... | |
uint16_t | Milliseconds = 0 |
Milliseconds (0-999) More... | |
uint8_t | Day = 0 |
Day of month (1-31) More... | |
uint8_t | DayofWeek = 0 |
Day of week (0-6 Sunday is day 0) More... | |
uint16_t | DayofYear = 0 |
Day of year (0-365) More... | |
uint8_t | Month = 0 |
Month (0-11 Jan is month 0) More... | |
uint16_t | Year = 0 |
Full Year number. More... | |
Date and time class.
Date and time functions mostly work with Unix time, the quantity of seconds since 00:00:00 1970-01-01. There is no support for leap seconds which are added (and in theory, removed) occasionally to compensate for earth rotation variation. This means that timespan calculation and free-running clocks may be inaccurate if they span leap seconds. To facilitate leap seconds, reference must be made to leap second table. This will not be done within the Sming framework and must be handled by application code if required.
|
inline |
Instantiate an uninitialised date and time object.
|
inline |
Instantiate a date and time object from a Unix timestamp.
time | Unix time to assign to object |
void DateTime::addMilliseconds | ( | long | add | ) |
Add time to date time object.
add | Quantity of milliseconds to add to object |
|
inlinestatic |
Convert from Unix time to individual time components.
timep | Unix time date value to convert |
psec | Pointer to integer to hold resulting seconds |
pmin | Pointer to integer to hold resulting minutes |
phour | Pointer to integer to hold resulting hour |
pday | Pointer to integer to hold resulting day of month |
pwday | Pointer to integer to hold resulting day of week |
pmonth | Pointer to integer to hold resulting month |
pyear | Pointer to integer to hold resulting year |
|
inlinestatic |
Convert from individual time components to Unix time.
sec | Seconds |
min | Minutes |
hour | Hours |
day | Days |
month | Month (0-11, Jan=0, Feb=1, ...Dec=11) |
year | Year (1901-2036), either full 4 digit year or 2 digits for 1970-2036 |
String DateTime::format | ( | const char * | formatString | ) |
Create string formatted with time and date placeholders.
formatString | String including date and time formatting |
String | Formatted string |
Param | Description | Locale |
---|---|---|
%a | Abbreviated weekday name | * |
%A | Full weekday name | * |
%b | Abbreviated month name | * |
%B | Full month name | * |
%c | Locale preferred date and time format | * |
%C | Century number (2 digits) | |
%d | Day of month as decimal number with leading zero (2 digits) | |
%D | US date format (mm/dd/yyyy) | |
%e | Day of month as decimal number with leading space (2 digits) | |
%F | ISO 8601 date format (YYYY-mm-dd) | |
%h | Equivalent to %b | * |
%H | Hour as a decimal number using a 24-hour clock (range 00 to 23) | |
%I | Hour as a decimal number using a 12-hour clock (range 00 to 12) | |
%j | Day of the year as a decimal number (range 001 to 366) | |
%m | Month as a decimal number (range 01 to 12) | |
%M | Minute as a decimal number (range 00 to 59) | |
%n | Newline | |
%p | Meridiem indicator: AM or PM. Midnight is AM and noon is PM | |
%r | Locale 12-hour clock time notation. This is equivalent to %I:%M:%S %p | * |
%R | Time in 24-hour notation (HH:MM) | |
%S | Second as a decimal number (range 00 to 60) | |
%t | Horizontal tab | |
%T | Time in 24-hour notation (HH:MM:SS) | |
%u | Day of the week as a decimal (range 1 to 7, Monday is 1) | |
%U | Week number as a decimal number (range 00 to 53, first Sunday as the first day of week 01) | |
%V | ISO 8601 week number as a decimal number (range 01 to 53, where week 1 is the first week including a Thursday) | |
%w | Day of the week as a decimal (range 0 to 6, Sunday is 0) | |
%W | Week number as a decimal number (range 00 to 53, first Monday as the first day of week 01) | |
%x | Locale preferred date representation | * |
%X | Locale preferred time representation | * |
%y | Year as a decimal number without a century (range 00 to 99) | |
%Y | Year as a decimal number (range 1970 to ...) | |
%% | Percent sign |
Create string formatted with time and date placeholders.
formatString | String including date and time formatting |
String | Formatted string |
bool DateTime::fromHttpDate | ( | const String & | httpDate | ) |
Parse a HTTP full date and set time and date.
httpDate | HTTP full date in RFC 1123 format, e.g. Sun, 06 Nov 1994 08:49:37 GMT |
bool | True on success |
|
static |
Convert from Unix time to individual time components.
timep | Unix time date value to convert |
psec | Pointer to integer to hold resulting seconds |
pmin | Pointer to integer to hold resulting minutes |
phour | Pointer to integer to hold resulting hour |
pday | Pointer to integer to hold resulting day of month |
pwday | Pointer to integer to hold resulting day of week |
pmonth | Pointer to integer to hold resulting month |
pyear | Pointer to integer to hold resulting year |
|
inlinestatic |
fromUnixTime(time_t, uint8_t*, uint8_t*, uint8_t*, uint8_t*, uint8_t*, uint8_t*, uint16_t*)
bool DateTime::isNull | ( | ) |
Check if time date object is initialised.
True | if object has no value. False if initialised. |
|
inline |
Get current Unix time.
time_t | Quantity of seconds since 00:00:00 1970-01-01 |
|
inline |
Parse a HTTP full date and set time and date.
httpDate | HTTP full date in RFC 1123 format, e.g. Sun, 06 Nov 1994 08:49:37 GMT |
bool | True on success |
fromHttpDate()
instead void DateTime::setTime | ( | time_t | time | ) |
Set time using Unix timestamp.
time | Unix time to set object time to |
|
inline |
Set time using time and date component values.
sec | Seconds |
min | Minutes |
day | Day of month |
month | Month (0=Jan, 11=Dec) |
year | Year |
String DateTime::toFullDateTimeString | ( | ) |
Get human readable date and time.
String | Date and time in format DD.MM.YYYY hh:mm:ss |
String DateTime::toHTTPDate | ( | ) |
Get human readable date and time.
String | Date and time in format DDD, DD MMM YYYY hh:mm:ss GMT |
String DateTime::toISO8601 | ( | ) |
Get human readable date and time.
String | Date and time in format YYYY-MM-DDThh:mm:ssZ |
String DateTime::toShortDateString | ( | ) |
Get human readable date.
String | Date in requested format, e.g. DD.MM.YYYY |
String DateTime::toShortTimeString | ( | bool | includeSeconds = false | ) |
Get human readable time.
includeSeconds | True to include seconds (Default: false) |
String | Time in format hh:mm or hh:mm:ss |
time_t DateTime::toUnixTime | ( | ) |
Get Unix time.
time_t | Unix time, quantity of seconds since 00:00:00 1970-01-01 |
|
static |
Convert from individual time components to Unix time.
sec | Seconds |
min | Minutes |
hour | Hours |
day | Days |
month | Month (0-11, Jan=0, Feb=1, ...Dec=11) |
year | Year (1901-2036), either full 4 digit year or 2 digits for 1970-2036 |
uint8_t DateTime::Day = 0 |
Day of month (1-31)
uint8_t DateTime::DayofWeek = 0 |
Day of week (0-6 Sunday is day 0)
uint16_t DateTime::DayofYear = 0 |
Day of year (0-365)
uint8_t DateTime::Hour = 0 |
Hour (0-23)
uint16_t DateTime::Milliseconds = 0 |
Milliseconds (0-999)
uint8_t DateTime::Minute = 0 |
Minute (0-59)
uint8_t DateTime::Month = 0 |
Month (0-11 Jan is month 0)
uint8_t DateTime::Second = 0 |
Second (0-59)
uint16_t DateTime::Year = 0 |
Full Year number.