mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:37:44 +00:00
AK+LibC+LibCore: Add a days_in_year function
This commit is contained in:
parent
a7a18b478e
commit
2236385e1f
3 changed files with 13 additions and 8 deletions
|
@ -70,10 +70,10 @@ static void time_to_tm(struct tm* tm, time_t t)
|
|||
tm->tm_wday /= __seconds_per_day;
|
||||
|
||||
int year = 1970;
|
||||
for (; t >= (365 + is_leap_year(year)) * __seconds_per_day; ++year)
|
||||
t -= (365 + is_leap_year(year)) * __seconds_per_day;
|
||||
for (; t >= days_in_year(year) * __seconds_per_day; ++year)
|
||||
t -= days_in_year(year) * __seconds_per_day;
|
||||
for (; t < 0; --year)
|
||||
t += (365 + is_leap_year(year - 1)) * __seconds_per_day;
|
||||
t += days_in_year(year - 1) * __seconds_per_day;
|
||||
ASSERT(t >= 0);
|
||||
|
||||
int days = t / __seconds_per_day;
|
||||
|
@ -275,7 +275,7 @@ size_t strftime(char* destination, size_t max_size, const char* format, const st
|
|||
if (tm->tm_yday >= 7 - wday_of_year_beginning)
|
||||
--week_number;
|
||||
else {
|
||||
const int days_of_last_year = 365 + is_leap_year(tm->tm_year + 1900 - 1);
|
||||
const int days_of_last_year = days_in_year(tm->tm_year + 1900 - 1);
|
||||
const int wday_of_last_year_beginning = (wday_of_year_beginning + 6 * days_of_last_year) % 7;
|
||||
week_number = (days_of_last_year + wday_of_last_year_beginning) / 7 + 1;
|
||||
if (wday_of_last_year_beginning > 3)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue