ISO8601d: Added ::daysInYear and tests

This commit is contained in:
Paul Beckingham 2015-09-26 13:57:10 -04:00
parent d8eb0ac0da
commit 965415d7a4
3 changed files with 13 additions and 1 deletions

View file

@ -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)

View file

@ -46,6 +46,7 @@ public:
static bool leapYear (int);
static int daysInMonth (int, int);
static int daysInYear (int);
static int dayOfWeek (const std::string&);

View file

@ -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");