8 bool is_leap_year(uint32_t
year) {
return (year % 4) == 0 && ((year % 100) != 0 || (year % 400) == 0); }
11 static const uint8_t DAYS_IN_MONTH[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
12 uint8_t days = DAYS_IN_MONTH[
month];
19 struct tm c_tm = this->
to_c_tm();
20 return ::strftime(buffer, buffer_len, format, &c_tm);
24 res.
second = uint8_t(c_tm->tm_sec);
25 res.minute = uint8_t(c_tm->tm_min);
26 res.hour = uint8_t(c_tm->tm_hour);
27 res.day_of_week = uint8_t(c_tm->tm_wday + 1);
28 res.day_of_month = uint8_t(c_tm->tm_mday);
29 res.day_of_year = uint16_t(c_tm->tm_yday + 1);
30 res.month = uint8_t(c_tm->tm_mon + 1);
31 res.year = uint16_t(c_tm->tm_year + 1900);
32 res.is_dst = bool(c_tm->tm_isdst);
33 res.timestamp = c_time;
38 c_tm.tm_sec = this->
second;
39 c_tm.tm_min = this->
minute;
40 c_tm.tm_hour = this->
hour;
42 c_tm.tm_mon = this->
month - 1;
43 c_tm.tm_year = this->
year - 1900;
46 c_tm.tm_isdst = this->
is_dst;
51 timestr.resize(format.size() * 4);
52 struct tm c_tm = this->
to_c_tm();
53 size_t len =
::strftime(×tr[0], timestr.size(), format.c_str(), &c_tm);
55 if (timestr.size() >= 128) {
60 timestr.resize(timestr.size() * 2);
61 len =
::strftime(×tr[0], timestr.size(), format.c_str(), &c_tm);
76 if (sscanf(time_to_parse.c_str(),
"%04hu-%02hhu-%02hhu %02hhu:%02hhu:%02hhu %n", &
year, &
month, &
day,
80 num == time_to_parse.size()) {
87 }
else if (sscanf(time_to_parse.c_str(),
"%04hu-%02hhu-%02hhu %02hhu:%02hhu %n", &
year, &
month, &
day,
90 num == time_to_parse.size()) {
97 }
else if (sscanf(time_to_parse.c_str(),
"%02hhu:%02hhu:%02hhu %n", &
hour, &
minute, &
second, &num) == 3 &&
98 num == time_to_parse.size()) {
102 }
else if (sscanf(time_to_parse.c_str(),
"%02hhu:%02hhu %n", &
hour, &
minute, &num) == 2 &&
103 num == time_to_parse.size()) {
107 }
else if (sscanf(time_to_parse.c_str(),
"%04hu-%02hhu-%02hhu %n", &
year, &
month, &
day, &num) == 3 &&
108 num == time_to_parse.size()) {
139 uint16_t days_in_year = (this->
year % 4 == 0) ? 366 : 365;
156 uint16_t days_in_year = (this->
year % 4 == 0) ? 366 : 365;
170 for (
int i = 1970; i < this->
year; i++)
173 if (use_day_of_year) {
176 for (
int i = 1; i < this->
month; i++)
202 time_t now = ::time(
nullptr);
205 bool negative = utc.hour > local.hour && local.day_of_year <= utc.day_of_year;
207 if (utc.minute > local.minute) {
211 offset += (local.minute - utc.minute) * 60;
214 offset -= (utc.hour - local.hour) * 3600;
216 if (utc.hour > local.hour) {
219 offset += (local.hour - utc.hour) * 3600;
232 if (current >= end) {
static ESPTime from_epoch_utc(time_t epoch)
Convert an UTC epoch timestamp to a UTC time ESPTime instance.
size_t strftime(char *buffer, size_t buffer_len, const char *format)
Convert this ESPTime struct to a null-terminated c string buffer as specified by the format argument...
static int32_t timezone_offset()
A more user-friendly version of struct tm from time.h.
static ESPTime from_c_tm(struct tm *c_tm, time_t c_time)
Convert a C tm struct instance with a C unix epoch timestamp to an ESPTime instance.
bool is_dst
daylight saving time flag
void increment_day()
Increment this clock instance by one day.
uint16_t day_of_year
day of the year [1-366]
bool operator<=(ESPTime other)
void increment_second()
Increment this clock instance by one second.
uint8_t days_in_month(uint8_t month, uint16_t year)
static ESPTime from_epoch_local(time_t epoch)
Convert an UTC epoch timestamp to a local time ESPTime instance.
bool operator>(ESPTime other)
bool increment_time_value(T ¤t, uint16_t begin, uint16_t end)
uint8_t second
seconds after the minute [0-60]
time_t timestamp
unix epoch time (seconds since UTC Midnight January 1, 1970)
struct tm to_c_tm()
Convert this ESPTime instance back to a tm struct.
uint8_t minute
minutes after the hour [0-59]
bool operator==(ESPTime other)
uint8_t day_of_week
day of the week; sunday=1 [1-7]
bool is_leap_year(uint32_t year)
void recalc_timestamp_local(bool use_day_of_year=true)
Recalculate the timestamp field from the other fields of this ESPTime instance assuming local fields...
Implementation of SPI Controller mode.
void recalc_timestamp_utc(bool use_day_of_year=true)
Recalculate the timestamp field from the other fields of this ESPTime instance (must be UTC)...
uint8_t month
month; january=1 [1-12]
uint8_t hour
hours since midnight [0-23]
bool operator<(ESPTime other)
uint8_t day_of_month
day of the month [1-31]
bool operator>=(ESPTime other)
bool fields_in_range() const
Check if all time fields of this ESPTime are in range.
static bool strptime(const std::string &time_to_parse, ESPTime &esp_time)
Convert a string to ESPTime struct as specified by the format argument.