- Now properly parses dates according to specified date format.

This commit is contained in:
Paul Beckingham 2008-06-12 23:58:58 -04:00
parent fd7bb9daa9
commit 8d90035bbc
5 changed files with 44 additions and 9 deletions

View file

@ -8,6 +8,7 @@ represents a feature release, and the z represents a patch.
1.2.0 (?)
+ Bug: "dateformat" configuration variable used to display dates, but not parse them
+ "task list x" now performs a caseless comparison between "x" and the description
+ Task sub projects supported.
------ reality -----------------------------------

View file

@ -136,7 +136,7 @@ void Config::createDefault (const std::string& file)
set ("data.location", taskDir);
set ("command.logging", "off");
set ("confirmation", "yes");
set ("next", 2);
set ("next", 1);
set ("curses", "on");
set ("color", "on");
set ("color.overdue", "red");

View file

@ -69,7 +69,7 @@ Date::Date (const std::string& mdy, const std::string format /* = "m/d/Y" */)
{
switch (format[f])
{
// Single digit.
// Single or double digit.
case 'm':
if (i >= mdy.length () ||
! ::isdigit (mdy[i]))
@ -77,8 +77,18 @@ Date::Date (const std::string& mdy, const std::string format /* = "m/d/Y" */)
throw std::string ("\"") + mdy + "\" is not a valid date.";
}
month = ::atoi (mdy.substr (i, 1).c_str ());
++i;
if (i + 1 < mdy.length () &&
mdy[i + 0] == '1' &&
(mdy[i + 1] == '0' || mdy[i + 1] == '1' || mdy[i + 1] == '2'))
{
month = ::atoi (mdy.substr (i, 2).c_str ());
i += 2;
}
else
{
month = ::atoi (mdy.substr (i, 1).c_str ());
++i;
}
break;
case 'd':
@ -88,8 +98,18 @@ Date::Date (const std::string& mdy, const std::string format /* = "m/d/Y" */)
throw std::string ("\"") + mdy + "\" is not a valid date.";
}
day = ::atoi (mdy.substr (i, 1).c_str ());
++i;
if (i + 1 < mdy.length () &&
(mdy[i + 0] == '1' || mdy[i + 0] == '2' || mdy[i + 0] == '3') &&
::isdigit (mdy[i + 1]))
{
day = ::atoi (mdy.substr (i, 2).c_str ());
i += 2;
}
else
{
day = ::atoi (mdy.substr (i, 1).c_str ());
++i;
}
break;
// Double digit.

View file

@ -952,8 +952,6 @@ void handleInfo (const TDB& tdb, T& task, Config& conf)
if (due.length ())
{
Date dt (::atoi (due.c_str ()));
overdue = (dt < now) ? true : false;
now += 7 * 86400;
imminent = dt < now ? true : false;

View file

@ -9,7 +9,7 @@
////////////////////////////////////////////////////////////////////////////////
int main (int argc, char** argv)
{
plan (52);
plan (63);
Date now;
Date yesterday;
@ -27,6 +27,8 @@ int main (int argc, char** argv)
ok (Date::leapYear (2008), "2008 is a leap year");
notok (Date::leapYear (2007), "2007 is not a leap year");
ok (Date::leapYear (2000), "2000 is a leap year");
ok (Date::leapYear (1900), "1900 is a leap year");
is (Date::daysInMonth (2, 2008), 29, "29 days in February 2008");
is (Date::daysInMonth (2, 2007), 28, "28 days in February 2007");
@ -91,6 +93,20 @@ int main (int argc, char** argv)
is (fromString3.day (), 1, "ctor (std::string) -> d");
is (fromString3.year (), 2008, "ctor (std::string) -> y");
Date fromString4 ("12/31/2007");
is (fromString4.month (), 12, "ctor (std::string) -> m");
is (fromString4.day (), 31, "ctor (std::string) -> d");
is (fromString4.year (), 2007, "ctor (std::string) -> y");
Date fromString5 ("12/31/2007", "m/d/Y");
is (fromString5.month (), 12, "ctor (std::string) -> m");
is (fromString5.day (), 31, "ctor (std::string) -> d");
is (fromString5.year (), 2007, "ctor (std::string) -> y");
Date fromString6 ("20071231", "YMD");
is (fromString6.month (), 12, "ctor (std::string) -> m");
is (fromString6.day (), 31, "ctor (std::string) -> d");
is (fromString6.year (), 2007, "ctor (std::string) -> y");
return 0;
}