mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
ISO8601d: Added ::daysInMonth and tests
This commit is contained in:
parent
6f5d07dcd4
commit
d8eb0ac0da
3 changed files with 18 additions and 1 deletions
|
@ -806,6 +806,18 @@ bool ISO8601d::leapYear (int year)
|
|||
! (year % 400);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Static
|
||||
int ISO8601d::daysInMonth (int month, int year)
|
||||
{
|
||||
static int days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
||||
|
||||
if (month == 2 && ISO8601d::leapYear (year))
|
||||
return 29;
|
||||
|
||||
return days[month - 1];
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Static
|
||||
int ISO8601d::dayOfWeek (const std::string& input)
|
||||
|
|
|
@ -45,6 +45,7 @@ public:
|
|||
bool parse (const std::string&, std::string::size_type&, const std::string& format = "");
|
||||
|
||||
static bool leapYear (int);
|
||||
static int daysInMonth (int, int);
|
||||
|
||||
static int dayOfWeek (const std::string&);
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ void testParse (
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
int main (int argc, char** argv)
|
||||
{
|
||||
UnitTest t (792);
|
||||
UnitTest t (794);
|
||||
|
||||
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 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");
|
||||
|
||||
t.is (ISO8601d::dayOfWeek ("SUNDAY"), 0, "SUNDAY == 0");
|
||||
t.is (ISO8601d::dayOfWeek ("sunday"), 0, "sunday == 0");
|
||||
t.is (ISO8601d::dayOfWeek ("Sunday"), 0, "Sunday == 0");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue