mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
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:
parent
2ab1df77df
commit
3c2987f53f
4 changed files with 82 additions and 1 deletions
10
src/Date.cpp
10
src/Date.cpp
|
@ -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.";
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue