mirror of
https://github.com/esphome/esphome.git
synced 2024-12-22 13:34:54 +01:00
Add increment_day function to ESPTime (#2955)
This commit is contained in:
parent
6a2c58fcc0
commit
ef5d959788
2 changed files with 19 additions and 0 deletions
|
@ -131,6 +131,23 @@ void ESPTime::increment_second() {
|
|||
this->year++;
|
||||
}
|
||||
}
|
||||
void ESPTime::increment_day() {
|
||||
this->timestamp += 86400;
|
||||
|
||||
// increment day
|
||||
increment_time_value(this->day_of_week, 1, 8);
|
||||
|
||||
if (increment_time_value(this->day_of_month, 1, days_in_month(this->month, this->year) + 1)) {
|
||||
// day of month roll-over, increment month
|
||||
increment_time_value(this->month, 1, 13);
|
||||
}
|
||||
|
||||
uint16_t days_in_year = (this->year % 4 == 0) ? 366 : 365;
|
||||
if (increment_time_value(this->day_of_year, 1, days_in_year + 1)) {
|
||||
// day of year roll-over, increment year
|
||||
this->year++;
|
||||
}
|
||||
}
|
||||
void ESPTime::recalc_timestamp_utc(bool use_day_of_year) {
|
||||
time_t res = 0;
|
||||
|
||||
|
|
|
@ -90,6 +90,8 @@ struct ESPTime {
|
|||
|
||||
/// Increment this clock instance by one second.
|
||||
void increment_second();
|
||||
/// Increment this clock instance by one day.
|
||||
void increment_day();
|
||||
bool operator<(ESPTime other);
|
||||
bool operator<=(ESPTime other);
|
||||
bool operator==(ESPTime other);
|
||||
|
|
Loading…
Reference in a new issue