ISO8601d: Added ::leapYear and tests
This commit is contained in:
@@ -798,6 +798,14 @@ bool ISO8601p::parse (const std::string& input, std::string::size_type& start)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Static
|
||||||
|
bool ISO8601d::leapYear (int year)
|
||||||
|
{
|
||||||
|
return ((! (year % 4)) && (year % 100)) ||
|
||||||
|
! (year % 400);
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Static
|
// Static
|
||||||
int ISO8601d::dayOfWeek (const std::string& input)
|
int ISO8601d::dayOfWeek (const std::string& input)
|
||||||
@@ -817,6 +825,7 @@ int ISO8601d::dayOfWeek (const std::string& input)
|
|||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Static
|
||||||
int ISO8601d::length (const std::string& format)
|
int ISO8601d::length (const std::string& format)
|
||||||
{
|
{
|
||||||
int len = 0;
|
int len = 0;
|
||||||
|
|||||||
@@ -44,6 +44,8 @@ public:
|
|||||||
operator time_t () const;
|
operator time_t () const;
|
||||||
bool parse (const std::string&, std::string::size_type&, const std::string& format = "");
|
bool parse (const std::string&, std::string::size_type&, const std::string& format = "");
|
||||||
|
|
||||||
|
static bool leapYear (int);
|
||||||
|
|
||||||
static int dayOfWeek (const std::string&);
|
static int dayOfWeek (const std::string&);
|
||||||
|
|
||||||
static int length (const std::string&);
|
static int length (const std::string&);
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ void testParse (
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
int main (int argc, char** argv)
|
int main (int argc, char** argv)
|
||||||
{
|
{
|
||||||
UnitTest t (788);
|
UnitTest t (792);
|
||||||
|
|
||||||
ISO8601d iso;
|
ISO8601d iso;
|
||||||
std::string::size_type start = 0;
|
std::string::size_type start = 0;
|
||||||
@@ -218,6 +218,12 @@ int main (int argc, char** argv)
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
// Leap year.
|
||||||
|
t.ok (ISO8601d::leapYear (2008), "2008 is a leap year");
|
||||||
|
t.notok (ISO8601d::leapYear (2007), "2007 is not 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.is (ISO8601d::dayOfWeek ("SUNDAY"), 0, "SUNDAY == 0");
|
t.is (ISO8601d::dayOfWeek ("SUNDAY"), 0, "SUNDAY == 0");
|
||||||
t.is (ISO8601d::dayOfWeek ("sunday"), 0, "sunday == 0");
|
t.is (ISO8601d::dayOfWeek ("sunday"), 0, "sunday == 0");
|
||||||
t.is (ISO8601d::dayOfWeek ("Sunday"), 0, "Sunday == 0");
|
t.is (ISO8601d::dayOfWeek ("Sunday"), 0, "Sunday == 0");
|
||||||
|
|||||||
Reference in New Issue
Block a user