diff options
author | Nico Weber <thakis@chromium.org> | 2020-08-25 19:19:16 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-08-26 08:52:07 +0200 |
commit | c85e679e2d802159f7eb1a70a1667dd20dea0379 (patch) | |
tree | 9b99e1274e82e67fc40f3bf06d8ef1162ed3afe0 /Libraries/LibCore | |
parent | 2c1b84b3e10e67d6aeb3006f7535b8990355d769 (diff) | |
download | serenity-c85e679e2d802159f7eb1a70a1667dd20dea0379.zip |
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.
Diffstat (limited to 'Libraries/LibCore')
-rw-r--r-- | Libraries/LibCore/DateTime.cpp | 8 |
1 files changed, 1 insertions, 7 deletions
diff --git a/Libraries/LibCore/DateTime.cpp b/Libraries/LibCore/DateTime.cpp index a1cd35cc7b..c4062699cc 100644 --- a/Libraries/LibCore/DateTime.cpp +++ b/Libraries/LibCore/DateTime.cpp @@ -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 |