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
commit a7a18b478e
Notes: sideshowbarker 2024-07-19 03:08:27 +09:00
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;
}
}