diff --git a/src/ISO8601.cpp b/src/ISO8601.cpp index a8ef2e6e6..df30ac7e7 100644 --- a/src/ISO8601.cpp +++ b/src/ISO8601.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -825,6 +826,30 @@ int ISO8601d::daysInYear (int year) return ISO8601d::leapYear (year) ? 366 : 365; } +//////////////////////////////////////////////////////////////////////////////// +std::string ISO8601d::monthName (int month) +{ + static const char* months[12] = + { + STRING_DATE_JANUARY, + STRING_DATE_FEBRUARY, + STRING_DATE_MARCH, + STRING_DATE_APRIL, + STRING_DATE_MAY, + STRING_DATE_JUNE, + STRING_DATE_JULY, + STRING_DATE_AUGUST, + STRING_DATE_SEPTEMBER, + STRING_DATE_OCTOBER, + STRING_DATE_NOVEMBER, + STRING_DATE_DECEMBER, + }; + + assert (month > 0); + assert (month <= 12); + return ucFirst (months[month - 1]); +} + //////////////////////////////////////////////////////////////////////////////// // Static int ISO8601d::dayOfWeek (const std::string& input) diff --git a/src/ISO8601.h b/src/ISO8601.h index ff083ce05..d82a9895b 100644 --- a/src/ISO8601.h +++ b/src/ISO8601.h @@ -47,6 +47,7 @@ public: static bool leapYear (int); static int daysInMonth (int, int); static int daysInYear (int); + static std::string monthName (int); static int dayOfWeek (const std::string&); diff --git a/test/iso8601d.t.cpp b/test/iso8601d.t.cpp index 98f2433e0..61aaad248 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 (796); + UnitTest t (808); ISO8601d iso; std::string::size_type start = 0; @@ -232,6 +232,20 @@ int main (int argc, char** argv) t.is (ISO8601d::daysInMonth (2, 2008), 29, "29 days in February 2008"); t.is (ISO8601d::daysInMonth (2, 2007), 28, "28 days in February 2007"); + // Names. + t.is (ISO8601d::monthName (1), "January", "1 = January"); + t.is (ISO8601d::monthName (2), "February", "2 = February"); + t.is (ISO8601d::monthName (3), "March", "3 = March"); + t.is (ISO8601d::monthName (4), "April", "4 = April"); + t.is (ISO8601d::monthName (5), "May", "5 = May"); + t.is (ISO8601d::monthName (6), "June", "6 = June"); + t.is (ISO8601d::monthName (7), "July", "7 = July"); + t.is (ISO8601d::monthName (8), "August", "8 = August"); + t.is (ISO8601d::monthName (9), "September", "9 = September"); + t.is (ISO8601d::monthName (10), "October", "10 = October"); + t.is (ISO8601d::monthName (11), "November", "11 = November"); + t.is (ISO8601d::monthName (12), "December", "12 = December"); + t.is (ISO8601d::dayOfWeek ("SUNDAY"), 0, "SUNDAY == 0"); t.is (ISO8601d::dayOfWeek ("sunday"), 0, "sunday == 0"); t.is (ISO8601d::dayOfWeek ("Sunday"), 0, "Sunday == 0");