mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +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
1
AUTHORS
1
AUTHORS
|
@ -50,4 +50,5 @@ Thanks to the following, who submitted detailed bug reports and excellent sugges
|
|||
Rich Mintz
|
||||
Seneca Cunningham
|
||||
Dirk Deimeke
|
||||
Michelle Crane
|
||||
|
||||
|
|
|
@ -35,6 +35,8 @@
|
|||
for which there are pending tasks (thanks to Dirk Deimeke).
|
||||
+ Fixed bug #414, that caused filtering on the presence or absence of tags
|
||||
containing Unicode characters to fail (thanks to Michal Josífko).
|
||||
+ Fixed bug #416, which caused sorting on a date to fail if the year was not
|
||||
included in the dateformat (thanks to Michelle Crane).
|
||||
|
||||
------ old releases ------------------------------
|
||||
|
||||
|
|
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.";
|
||||
|
||||
|
|
70
src/tests/datesort.t
Executable file
70
src/tests/datesort.t
Executable file
|
@ -0,0 +1,70 @@
|
|||
#! /usr/bin/perl
|
||||
################################################################################
|
||||
## task - a command line task list manager.
|
||||
##
|
||||
## Copyright 2006 - 2010, Paul Beckingham.
|
||||
## All rights reserved.
|
||||
##
|
||||
## This program is free software; you can redistribute it and/or modify it under
|
||||
## the terms of the GNU General Public License as published by the Free Software
|
||||
## Foundation; either version 2 of the License, or (at your option) any later
|
||||
## version.
|
||||
##
|
||||
## This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
## details.
|
||||
##
|
||||
## You should have received a copy of the GNU General Public License along with
|
||||
## this program; if not, write to the
|
||||
##
|
||||
## Free Software Foundation, Inc.,
|
||||
## 51 Franklin Street, Fifth Floor,
|
||||
## Boston, MA
|
||||
## 02110-1301
|
||||
## USA
|
||||
##
|
||||
################################################################################
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test::More tests => 6;
|
||||
|
||||
# Create the rc file.
|
||||
if (open my $fh, '>', 'datesort.rc')
|
||||
{
|
||||
print $fh "data.location=.\n",
|
||||
"dateformat=YMD\n",
|
||||
"report.small_list.description=Small list\n",
|
||||
"report.small_list.columns=due,description\n",
|
||||
"report.small_list.labels=Due,Description\n",
|
||||
"report.small_list.sort=due+\n",
|
||||
"report.small_list.filter=status:pending\n",
|
||||
"report.small_list.dateformat=MD\n";
|
||||
|
||||
close $fh;
|
||||
ok (-r 'datesort.rc', 'Created datesort.rc');
|
||||
}
|
||||
|
||||
qx{../task rc:datesort.rc add two due:20100201};
|
||||
qx{../task rc:datesort.rc add one due:20100101};
|
||||
qx{../task rc:datesort.rc add three due:20100301};
|
||||
|
||||
my $output = qx{../task rc:datesort.rc small_list};
|
||||
like ($output, qr/one.+two.+three/ms, 'Sorting by due+ with format MD works');
|
||||
|
||||
$output = qx{../task rc:datesort.rc rc.report.small_list.sort=due- small_list};
|
||||
like ($output, qr/three.+two.+one/ms, 'Sorting by due- with format MD works');
|
||||
|
||||
# Cleanup.
|
||||
unlink 'pending.data';
|
||||
ok (!-r 'pending.data', 'Removed pending.data');
|
||||
|
||||
unlink 'undo.data';
|
||||
ok (!-r 'undo.data', 'Removed undo.data');
|
||||
|
||||
unlink 'datesort.rc';
|
||||
ok (!-r 'datesort.rc', 'Removed datesort.rc');
|
||||
|
||||
exit 0;
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue