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

AK+LibC+LibCore: Add a days_in_year function

This commit is contained in:
Nico Weber 2020-08-25 20:17:19 -04:00 committed by Andreas Kling
parent a7a18b478e
commit 2236385e1f
3 changed files with 13 additions and 8 deletions

View file

@ -43,13 +43,18 @@ inline bool is_leap_year(int year)
return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
}
inline unsigned days_in_year(int year)
{
return 365 + is_leap_year(year);
}
inline int years_to_days_since_epoch(int year)
{
int days = 0;
for (int current_year = 1970; current_year < year; ++current_year)
days += 365 + is_leap_year(current_year);
days += days_in_year(current_year);
for (int current_year = year; current_year < 1970; ++current_year)
days -= 365 + is_leap_year(current_year);
days -= days_in_year(current_year);
return days;
}
@ -173,6 +178,7 @@ inline bool operator!=(const TimespecType& a, const TimespecType& b)
using AK::day_of_year;
using AK::days_in_month;
using AK::days_in_year;
using AK::is_leap_year;
using AK::timespec_add;
using AK::timespec_add_timeval;