mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 22:08:10 +00:00
AK+LibC+LibCore: Have fewer implementations of day_of_week
The implementation in LibC did a timestamp->day-of-week conversion which looks like a valuable thing to have. But we only need it in time_to_tm, where we already computed year/month/day -- so let's consolidate on the day_of_week function in DateTime (which is getting extracted to AK).
This commit is contained in:
parent
b9cbb4fd00
commit
1ab8939077
4 changed files with 20 additions and 12 deletions
|
@ -64,11 +64,6 @@ static const int __seconds_per_day = 60 * 60 * 24;
|
|||
|
||||
static void time_to_tm(struct tm* tm, time_t t)
|
||||
{
|
||||
tm->tm_wday = (4 * __seconds_per_day + t) % (7 * __seconds_per_day); // 1970-01-01 was a Thursday.
|
||||
if (tm->tm_wday < 0)
|
||||
tm->tm_wday += 7 * __seconds_per_day;
|
||||
tm->tm_wday /= __seconds_per_day;
|
||||
|
||||
int year = 1970;
|
||||
for (; t >= days_in_year(year) * __seconds_per_day; ++year)
|
||||
t -= days_in_year(year) * __seconds_per_day;
|
||||
|
@ -89,8 +84,9 @@ static void time_to_tm(struct tm* tm, time_t t)
|
|||
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;
|
||||
tm->tm_wday = day_of_week(year, month, tm->tm_mday);
|
||||
tm->tm_mon = month - 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