DATE65: Fixed bug when advancing one hour for DST

This commit is contained in:
Bobbi Webber-Manners 2020-09-05 01:06:00 -04:00
parent 694a48c648
commit 680e8c7a0b

View File

@ -40,6 +40,25 @@ char dst_tz_code[4];
int dst_tz_secs;
uint8_t exec_email_on_exit = 0;
/*
* Add an hour
*/
void add_hour(struct datetime *dt) {
++dt->hour;
if (dt->hour == 24) {
dt->hour = 0;
++dt->day;
if (dt->day > months[dt->month]) {
dt->day = 1;
++dt->month;
if (dt->month == 13) {
dt->month = 1;
++dt->year;
}
}
}
}
/*
* Is year a leap year?
*/
@ -427,7 +446,7 @@ int main(int argc, char *argv[])
datestr[24] = 0; // Remove carriage return
printf("%s", datestr);
if (dst) {
++dt.hour; // Spring forward!
add_hour(&dt); // Spring forward!
printf(" (%s)", dst ? dst_tz_code : nondst_tz_code);
}