1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:28: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:
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

@ -61,12 +61,7 @@ DateTime DateTime::from_timestamp(time_t timestamp)
unsigned DateTime::weekday() const
{
int target_year = m_year;
static const int seek_table[] = { 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 };
if (m_month < 3)
--target_year;
return (target_year + target_year / 4 - target_year / 100 + target_year / 400 + seek_table[m_month - 1] + m_day) % 7;
return ::day_of_week(m_year, m_month, m_day);
}
unsigned DateTime::days_in_month() const