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

AK+LibCore+Kernel: Have fewer implementations of day_of_year

The JS tests pointed out that the implementation in DateTime
had an off-by-one in the month when doing the leap year check,
so this change fixes that bug.
This commit is contained in:
Nico Weber 2020-08-25 19:19:16 -04:00 committed by Andreas Kling
parent 2c1b84b3e1
commit c85e679e2d
6 changed files with 57 additions and 60 deletions

View file

@ -28,6 +28,13 @@
namespace AK {
// Month and day start at 1. Month must be >= 1 and <= 12.
// The return value is 0-indexed, that is Jan 1 is day 0.
// Day may be negative or larger than the number of days
// in the given month. If day is negative enough, the result
// can be negative.
int day_of_year(int year, unsigned month, int day);
inline bool is_leap_year(int year)
{
return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
@ -161,6 +168,7 @@ inline bool operator!=(const TimespecType& a, const TimespecType& b)
}
using AK::day_of_year;
using AK::is_leap_year;
using AK::timespec_add;
using AK::timespec_add_timeval;