1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:17:36 +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:
Nico Weber 2020-08-25 20:32:32 -04:00 committed by Andreas Kling
parent b9cbb4fd00
commit 1ab8939077
4 changed files with 20 additions and 12 deletions

View file

@ -51,4 +51,14 @@ int days_in_month(int year, unsigned month)
bool is_long_month = (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12);
return is_long_month ? 31 : 30;
}
unsigned day_of_week(int year, unsigned month, int day)
{
ASSERT(month >= 1 && month <= 12);
static const int seek_table[] = { 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 };
if (month < 3)
--year;
return (year + year / 4 - year / 100 + year / 400 + seek_table[month - 1] + day) % 7;
}
}