1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 04:57:44 +00:00

AK+LibC+LibCore: Have fewer implementations of days_in_month

This commit is contained in:
Nico Weber 2020-08-25 20:11:12 -04:00 committed by Andreas Kling
parent dcb81fc199
commit a7a18b478e
4 changed files with 20 additions and 16 deletions

View file

@ -42,4 +42,13 @@ int day_of_year(int year, unsigned month, int day)
return day_of_year;
}
int days_in_month(int year, unsigned month)
{
ASSERT(month >= 1 && month <= 12);
if (month == 2)
return is_leap_year(year) ? 29 : 28;
bool is_long_month = (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12);
return is_long_month ? 31 : 30;
}
}