9 static const uint8_t DAYS_IN_MONTH[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
10 if (month == 2 && (year % 4 == 0))
12 return DAYS_IN_MONTH[
month];
16 struct tm c_tm = this->
to_c_tm();
17 return ::strftime(buffer, buffer_len, format, &c_tm);
22 res.
second = uint8_t(c_tm->tm_sec);
23 res.minute = uint8_t(c_tm->tm_min);
24 res.hour = uint8_t(c_tm->tm_hour);
25 res.day_of_week = uint8_t(c_tm->tm_wday + 1);
26 res.day_of_month = uint8_t(c_tm->tm_mday);
27 res.day_of_year = uint16_t(c_tm->tm_yday + 1);
28 res.month = uint8_t(c_tm->tm_mon + 1);
29 res.year = uint16_t(c_tm->tm_year + 1900);
30 res.is_dst = bool(c_tm->tm_isdst);
31 res.timestamp = c_time;
37 c_tm.tm_sec = this->
second;
38 c_tm.tm_min = this->
minute;
39 c_tm.tm_hour = this->
hour;
41 c_tm.tm_mon = this->
month - 1;
42 c_tm.tm_year = this->
year - 1900;
45 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;
157 uint16_t days_in_year = (this->
year % 4 == 0) ? 366 : 365;
171 for (
int i = 1970; i < this->
year; i++)
172 res += (i % 4 == 0) ? 366 : 365;
174 if (use_day_of_year) {
177 for (
int i = 1; i < this->
month; i++)
194 tm.tm_year = this->
year - 1900;
195 tm.tm_mon = this->
month - 1;
197 tm.tm_hour = this->
hour;
206 time_t now = ::time(
nullptr);
209 bool negative = utc.hour > local.hour && local.day_of_year <= utc.day_of_year;
211 if (utc.minute > local.minute) {
215 offset += (local.minute - utc.minute) * 60;
218 offset -= (utc.hour - local.hour) * 3600;
220 if (utc.hour > local.hour) {
223 offset += (local.hour - utc.hour) * 3600;
236 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...
void recalc_timestamp_local()
Recalculate the timestamp field from the other fields of this ESPTime instance assuming local fields...
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]
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.