Bug #416 - Sorting by due date with dateformat MD wrong

- Fixed bug #416, which caused sorting on a date to fail if the year was not
  included in the dateformat (thanks to Michelle Crane).
- Added unit tests.
This commit is contained in:
Paul Beckingham 2010-06-25 09:09:20 -04:00
parent 2ab1df77df
commit 3c2987f53f
4 changed files with 82 additions and 1 deletions

View file

@ -86,7 +86,7 @@ Date::Date (const std::string& mdy, const std::string& format /* = "m/d/Y" */)
{
int month = 0;
int day = 0;
int year = 0;
int year = -1; // So we can check later.
int hour = 0;
int minute = 0;
int second = 0;
@ -332,6 +332,14 @@ Date::Date (const std::string& mdy, const std::string& format /* = "m/d/Y" */)
}
}
// Default the year to the current year, for formats that lack Y/y.
if (year == -1)
{
time_t now = time (NULL);
struct tm* default_year = localtime (&now);
year = default_year->tm_year + 1900;
}
if (i < mdy.length ())
throw std::string ("\"") + mdy + "\" is not a valid date in " + format + " format.";