Relative dates

- eoq and soq to refer to the end and start of the quarter
  (thanks to David French)
This commit is contained in:
Federico Hernandez 2011-08-04 01:40:31 +02:00
parent e5ae145df2
commit 6e1ba161b1
5 changed files with 59 additions and 3 deletions

View file

@ -38,6 +38,7 @@
+ The configuration variable 'json.array' determines whether 'query' command + The configuration variable 'json.array' determines whether 'query' command
output is enclosed by '[...]'. output is enclosed by '[...]'.
+ The duration 'm' is now interpreted as 'months', not 'minutes'. + The duration 'm' is now interpreted as 'months', not 'minutes'.
+ New "eoq" and "soq" dates for the end and start of quarter.
# Tracked Features, sorted by ID. # Tracked Features, sorted by ID.
+ Added feature #278, which provides a more consistent command line grammar. + Added feature #278, which provides a more consistent command line grammar.

1
NEWS
View file

@ -24,6 +24,7 @@ New Features in taskwarrior 2.0.0
- The done, delete, start and stop commands now allow modification to the - The done, delete, start and stop commands now allow modification to the
task and annotations. task and annotations.
- New 'columns' command to list the supported columns and formats. - New 'columns' command to list the supported columns and formats.
- New 'eoq' and 'soq' dates to refer to the end and start of the quarter.
Please refer to the ChangeLog file for full details. There are too many to Please refer to the ChangeLog file for full details. There are too many to
list here. list here.

View file

@ -600,7 +600,7 @@ task ... due:1day
task ... due:9hrs task ... due:9hrs
.TP .TP
Start of (work) week (Monday), calendar week (Sunday or Monday), month and year Start of (work) week (Monday), calendar week (Sunday or Monday), month, quarter and year
.br .br
task ... due:sow task ... due:sow
.br .br
@ -610,10 +610,12 @@ task ... due:socw
.br .br
task ... due:som task ... due:som
.br .br
task ... due:soq
.br
task ... due:soy task ... due:soy
.TP .TP
End of (work) week (Friday), calendar week (Saturday or Sunday), month and year End of (work) week (Friday), calendar week (Saturday or Sunday), month, quarter and year
.br .br
task ... due:eow task ... due:eow
.br .br
@ -623,6 +625,8 @@ task ... due:eocw
.br .br
task ... due:eom task ... due:eom
.br .br
task ... due:eoq
.br
task ... due:eoy task ... due:eoy
.TP .TP

View file

@ -58,11 +58,13 @@ static const char* relatives[] =
"eoww", "eoww",
"eocw", "eocw",
"eom", "eom",
"eoq",
"eoy", "eoy",
"sow", "sow",
"soww", "soww",
"socw", "socw",
"som", "som",
"soq",
"soy", "soy",
"goodfriday", "goodfriday",
"easter", "easter",
@ -877,6 +879,25 @@ bool Date::isRelativeDate (const std::string& input)
mT = then.mT; mT = then.mT;
return true; return true;
} }
else if (found == "eoq")
{
int m = today.month ();
int y = today.year ();
int q;
if (m <= 3)
q = 3;
else if (m >= 4 && m <= 6)
q = 6;
else if (m >= 7 && m <= 9)
q = 9;
else
q = 12;
Date then (q,
Date::daysInMonth (q, y),
y);
mT = then.mT;
return true;
}
else if (found == "eoy") else if (found == "eoy")
{ {
Date then (12, 31, today.year ()); Date then (12, 31, today.year ());
@ -896,6 +917,25 @@ bool Date::isRelativeDate (const std::string& input)
mT = then.mT; mT = then.mT;
return true; return true;
} }
else if (found == "soq")
{
int m = today.month ();
int y = today.year ();
int q;
if (m <= 3)
q = 1;
else if (m >= 4 && m <= 6)
q = 4;
else if (m >= 7 && m <= 9)
q = 7;
else
q = 10;
Date then (q,
1,
y);
mT = then.mT;
return true;
}
else if (found == "soy") else if (found == "soy")
{ {
Date then (1, 1, today.year () + 1); Date then (1, 1, today.year () + 1);

View file

@ -34,7 +34,7 @@ Context context;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int main (int argc, char** argv) int main (int argc, char** argv)
{ {
UnitTest t (168); UnitTest t (174);
try try
{ {
@ -346,6 +346,16 @@ int main (int argc, char** argv)
t.is (later.day (), 18, "later -> d = 18"); t.is (later.day (), 18, "later -> d = 18");
t.is (later.year (), 2038, "later -> y = 2038"); t.is (later.year (), 2038, "later -> y = 2038");
// Quarters
Date soq ("soq");
Date eoq ("eoq");
t.is (soq.day (), 1, "soq is the first day of a month");
t.is (eoq.day () / 10, 3, "eoq is the 30th or 31th of a month");
t.is (soq.month () % 3, 1, "soq month is 1, 4, 7 or 10");
t.is (eoq.month () % 3, 0, "eoq month is 3, 6, 9 or 12");
t.ok (soq.sameYear (now), "soq is in same year as now");
t.ok (eoq.sameYear (now), "eoq is in same year as now");
// Date::sameHour // Date::sameHour
Date r17 ("6/7/2010 01:00:00", "m/d/Y H:N:S"); Date r17 ("6/7/2010 01:00:00", "m/d/Y H:N:S");
Date r18 ("6/7/2010 01:59:59", "m/d/Y H:N:S"); Date r18 ("6/7/2010 01:59:59", "m/d/Y H:N:S");