1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 03:27:44 +00:00

AK+LibCore+Kernel: Have fewer implementations of day_of_year

The JS tests pointed out that the implementation in DateTime
had an off-by-one in the month when doing the leap year check,
so this change fixes that bug.
This commit is contained in:
Nico Weber 2020-08-25 19:19:16 -04:00 committed by Andreas Kling
parent 2c1b84b3e1
commit c85e679e2d
6 changed files with 57 additions and 60 deletions

View file

@ -117,13 +117,7 @@ static time_t tm_to_time(struct tm* tm, long timezone_adjust_seconds)
}
int days = years_to_days_since_epoch(1900 + tm->tm_year);
tm->tm_yday = tm->tm_mday - 1;
for (int month = 0; month < tm->tm_mon; ++month)
tm->tm_yday += __days_per_month[month];
if (tm->tm_mon > 1 && is_leap_year(1900 + tm->tm_year))
++tm->tm_yday;
tm->tm_yday = day_of_year(1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday);
days += tm->tm_yday;
int seconds = tm->tm_hour * 3600 + tm->tm_min * 60 + tm->tm_sec;