mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 05:38:11 +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:
parent
2c1b84b3e1
commit
c85e679e2d
6 changed files with 57 additions and 60 deletions
|
@ -81,13 +81,7 @@ unsigned DateTime::days_in_month() const
|
|||
|
||||
unsigned DateTime::day_of_year() const
|
||||
{
|
||||
static const int seek_table[] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
|
||||
int day_of_year = seek_table[m_month - 1] + m_day;
|
||||
|
||||
if (is_leap_year() && m_month > 3)
|
||||
day_of_year++;
|
||||
|
||||
return day_of_year - 1;
|
||||
return ::day_of_year(m_year, m_month, m_day);
|
||||
}
|
||||
|
||||
bool DateTime::is_leap_year() const
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue