From 965415d7a48373be672e96d696538198bb840b76 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 26 Sep 2015 13:57:10 -0400 Subject: [PATCH] ISO8601d: Added ::daysInYear and tests --- src/ISO8601.cpp | 7 +++++++ src/ISO8601.h | 1 + test/iso8601d.t.cpp | 6 +++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/ISO8601.cpp b/src/ISO8601.cpp index 2a6ef6ddc..a8ef2e6e6 100644 --- a/src/ISO8601.cpp +++ b/src/ISO8601.cpp @@ -818,6 +818,13 @@ int ISO8601d::daysInMonth (int month, int year) return days[month - 1]; } +//////////////////////////////////////////////////////////////////////////////// +// Static +int ISO8601d::daysInYear (int year) +{ + return ISO8601d::leapYear (year) ? 366 : 365; +} + //////////////////////////////////////////////////////////////////////////////// // Static int ISO8601d::dayOfWeek (const std::string& input) diff --git a/src/ISO8601.h b/src/ISO8601.h index 34669e9af..ff083ce05 100644 --- a/src/ISO8601.h +++ b/src/ISO8601.h @@ -46,6 +46,7 @@ public: static bool leapYear (int); static int daysInMonth (int, int); + static int daysInYear (int); static int dayOfWeek (const std::string&); diff --git a/test/iso8601d.t.cpp b/test/iso8601d.t.cpp index b3a5bd60d..98f2433e0 100644 --- a/test/iso8601d.t.cpp +++ b/test/iso8601d.t.cpp @@ -71,7 +71,7 @@ void testParse ( //////////////////////////////////////////////////////////////////////////////// int main (int argc, char** argv) { - UnitTest t (794); + UnitTest t (796); ISO8601d iso; std::string::size_type start = 0; @@ -224,6 +224,10 @@ int main (int argc, char** argv) t.ok (ISO8601d::leapYear (2000), "2000 is a leap year"); t.notok (ISO8601d::leapYear (1900), "1900 is not a leap year"); + // Days in year. + t.is (ISO8601d::daysInYear (2016), 366, "366 days in 2016"); + t.is (ISO8601d::daysInYear (2015), 365, "365 days in 2015"); + // Days in month. t.is (ISO8601d::daysInMonth (2, 2008), 29, "29 days in February 2008"); t.is (ISO8601d::daysInMonth (2, 2007), 28, "28 days in February 2007");