Add increment_day function to ESPTime (#2955)

This commit is contained in:
Rebbe Pod 2022-01-24 15:54:46 -05:00 committed by GitHub
parent 6a2c58fcc0
commit ef5d959788
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View file

@ -131,6 +131,23 @@ void ESPTime::increment_second() {
this->year++; 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) { void ESPTime::recalc_timestamp_utc(bool use_day_of_year) {
time_t res = 0; time_t res = 0;

View file

@ -90,6 +90,8 @@ struct ESPTime {
/// Increment this clock instance by one second. /// Increment this clock instance by one second.
void increment_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); bool operator<=(ESPTime other);
bool operator==(ESPTime other); bool operator==(ESPTime other);