1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-10 18:10:56 +09:00

LibC: Slightly tweak tm_to_time

Only one of these loops runs even without the outer if, so omit it.
No behavior change, and a bit shorter and arguably a bit clearer.
This commit is contained in:
Nico Weber 2020-08-22 22:13:18 -04:00 committed by Andreas Kling
parent cec467fe35
commit fc28c9b085
Notes: sideshowbarker 2024-07-19 03:16:14 +09:00

View file

@ -96,13 +96,10 @@ static void time_to_tm(struct tm* tm, time_t t)
static time_t tm_to_time(struct tm* tm, long timezone_adjust_seconds)
{
int days = 0;
if (tm->tm_year >= 70) {
for (int year = 70; year < tm->tm_year; ++year)
days += 365 + __is_leap_year(1900 + year);
} else {
for (int year = tm->tm_year; year < 70; ++year)
days -= 365 + __is_leap_year(1900 + year);
}
for (int year = 70; year < tm->tm_year; ++year)
days += 365 + __is_leap_year(1900 + year);
for (int year = tm->tm_year; year < 70; ++year)
days -= 365 + __is_leap_year(1900 + year);
tm->tm_yday = tm->tm_mday - 1;
// FIXME: What if tm->tm_mon < 0 or tm->tm_mon > 12?