mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-10 18:10:56 +09:00
AK+LibC+LibCore: Have fewer implementations of days_in_month
This commit is contained in:
parent
dcb81fc199
commit
a7a18b478e
Notes:
sideshowbarker
2024-07-19 03:08:27 +09:00
Author: https://github.com/nico
Commit: a7a18b478e
Pull-request: https://github.com/SerenityOS/serenity/pull/3307
4 changed files with 20 additions and 16 deletions
|
@ -60,7 +60,6 @@ char* ctime(const time_t* t)
|
|||
return asctime(localtime(t));
|
||||
}
|
||||
|
||||
static const int __days_per_month[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
||||
static const int __seconds_per_day = 60 * 60 * 24;
|
||||
|
||||
static void time_to_tm(struct tm* tm, time_t t)
|
||||
|
@ -85,16 +84,13 @@ static void time_to_tm(struct tm* tm, time_t t)
|
|||
tm->tm_hour = remaining / 60;
|
||||
tm->tm_year = year - 1900;
|
||||
tm->tm_yday = days;
|
||||
tm->tm_mday = 1;
|
||||
if (is_leap_year(year) && days == 59)
|
||||
++tm->tm_mday;
|
||||
if (is_leap_year(year) && days >= 59)
|
||||
--days;
|
||||
|
||||
int month;
|
||||
for (month = 0; month < 11 && days >= __days_per_month[month]; ++month)
|
||||
days -= __days_per_month[month];
|
||||
tm->tm_mon = month;
|
||||
tm->tm_mday += days;
|
||||
for (month = 1; month < 12 && days >= days_in_month(year, month); ++month)
|
||||
days -= days_in_month(year, month);
|
||||
|
||||
tm->tm_mon = month - 1;
|
||||
tm->tm_mday = days + 1;
|
||||
}
|
||||
|
||||
static time_t tm_to_time(struct tm* tm, long timezone_adjust_seconds)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue