mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
ISO8601d: Added ::daysInYear and tests
This commit is contained in:
parent
d8eb0ac0da
commit
965415d7a4
3 changed files with 13 additions and 1 deletions
|
@ -818,6 +818,13 @@ int ISO8601d::daysInMonth (int month, int year)
|
||||||
return days[month - 1];
|
return days[month - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Static
|
||||||
|
int ISO8601d::daysInYear (int year)
|
||||||
|
{
|
||||||
|
return ISO8601d::leapYear (year) ? 366 : 365;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Static
|
// Static
|
||||||
int ISO8601d::dayOfWeek (const std::string& input)
|
int ISO8601d::dayOfWeek (const std::string& input)
|
||||||
|
|
|
@ -46,6 +46,7 @@ public:
|
||||||
|
|
||||||
static bool leapYear (int);
|
static bool leapYear (int);
|
||||||
static int daysInMonth (int, int);
|
static int daysInMonth (int, int);
|
||||||
|
static int daysInYear (int);
|
||||||
|
|
||||||
static int dayOfWeek (const std::string&);
|
static int dayOfWeek (const std::string&);
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,7 @@ void testParse (
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
int main (int argc, char** argv)
|
int main (int argc, char** argv)
|
||||||
{
|
{
|
||||||
UnitTest t (794);
|
UnitTest t (796);
|
||||||
|
|
||||||
ISO8601d iso;
|
ISO8601d iso;
|
||||||
std::string::size_type start = 0;
|
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.ok (ISO8601d::leapYear (2000), "2000 is a leap year");
|
||||||
t.notok (ISO8601d::leapYear (1900), "1900 is not 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.
|
// Days in month.
|
||||||
t.is (ISO8601d::daysInMonth (2, 2008), 29, "29 days in February 2008");
|
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::daysInMonth (2, 2007), 28, "28 days in February 2007");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue