From 96bd3ff8db7d039e25031363f808a4aaadf9fb90 Mon Sep 17 00:00:00 2001 From: Federico Hernandez Date: Wed, 28 Jul 2010 00:15:26 +0200 Subject: [PATCH] Feature #446 - start of {week, month, year} - Added sow (depending on rc.weekstart), som and soy as possible dates (similar to eow, eom and eoy). --- ChangeLog | 2 ++ NEWS | 2 ++ doc/man/task.1 | 8 ++++++++ src/Date.cpp | 24 +++++++++++++++++++++++- src/tests/date.t.cpp | 23 ++++++++++++++++------- 5 files changed, 51 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index b9043d6de..e079ecee7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -17,6 +17,8 @@ tasks, provide a new sort order and include the 'end' column. + Added feature #431, which improves feedback after running the 'log' command. + + Added feature #446, task supports now 'sow', 'som' and 'soy' as dates + for 'due', 'wait' and 'until' (thanks to T. Charles Yun). + New 'depends' column for custom reports. + New 'blocked' report for showing blocked tasks. + Improved man pages (thanks to Andy Lester). diff --git a/NEWS b/NEWS index 8fba22104..0950dc456 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,7 @@ New Features in task 1.9.3 - Now supports durations in dates, such as: $ task ... due:4d $ task ... due:3wks + - Now supports the beginning of the week, month and year in dates. Please refer to the ChangeLog file for full details. There are too many to list here. @@ -18,6 +19,7 @@ New commands in task 1.9.3 New configuration options in task 1.9.3 - journal.time, journal.time.start.annotation, journal.time.stop.annotation + - 'sow', 'som' and 'soy' are now accepted in dates Newly deprecated features in task 1.9.3 diff --git a/doc/man/task.1 b/doc/man/task.1 index 3900fe882..a431daf13 100644 --- a/doc/man/task.1 +++ b/doc/man/task.1 @@ -394,6 +394,14 @@ task ... due:eom .br task ... due:eoy +.TP +Start of week (Sunday or Monday), month and year +task ... due:sow +.br +task ... due:som +.br +task ... due:soy + .TP Next occurring weekday task ... due:fri diff --git a/src/Date.cpp b/src/Date.cpp index 8aaa1187c..049d64c28 100644 --- a/src/Date.cpp +++ b/src/Date.cpp @@ -887,6 +887,9 @@ bool Date::isRelativeDate (const std::string& input) supported.push_back ("eow"); supported.push_back ("eom"); supported.push_back ("eoy"); + supported.push_back ("sow"); + supported.push_back ("som"); + supported.push_back ("soy"); supported.push_back ("goodfriday"); supported.push_back ("easter"); supported.push_back ("eastermonday"); @@ -903,11 +906,16 @@ bool Date::isRelativeDate (const std::string& input) // If day name. int dow; if ((dow = Date::dayOfWeek (found)) != -1 || - found == "eow") + found == "eow" || + found == "eocw" || + found == "sow") { if (found == "eow") dow = 5; + if (found == "sow") + dow =Date::dayOfWeek (context.config.get ("weekstart")); + if (today.dayOfWeek () >= dow) today += (dow - today.dayOfWeek () + 7) * 86400; else @@ -958,6 +966,20 @@ bool Date::isRelativeDate (const std::string& input) mT = then.mT; return true; } + else if (found == "som") + { + Date then (today.month (), + 1, + today.year ()); + mT = then.mT; + return true; + } + else if (found == "soy") + { + Date then (1, 1, today.year ()); + mT = then.mT; + return true; + } else if (found == "goodfriday") { Date then (Date::easter(today.year())); diff --git a/src/tests/date.t.cpp b/src/tests/date.t.cpp index 5f235c708..dd818642f 100644 --- a/src/tests/date.t.cpp +++ b/src/tests/date.t.cpp @@ -34,7 +34,7 @@ Context context; //////////////////////////////////////////////////////////////////////////////// int main (int argc, char** argv) { - UnitTest t (144); + UnitTest t (147); try { @@ -307,13 +307,22 @@ int main (int argc, char** argv) Date r13 ("eoy"); t.ok (r13.sameYear (now), "eoy in same year as now"); - // Date::sameHour - Date r14 ("6/7/2010 01:00:00", "m/d/Y H:N:S"); - Date r15 ("6/7/2010 01:59:59", "m/d/Y H:N:S"); - t.ok (r14.sameHour (r15), "two dates within the same hour"); + Date r14 ("sow"); + t.ok (r14 < now + (8 * 86400), "sow < 7 days away"); - Date r16 ("6/7/2010 00:59:59", "m/d/Y H:N:S"); - t.notok (r14.sameHour (r16), "two dates not within the same hour"); + Date r15 ("som"); + t.ok (r15.sameMonth (now), "eom in same month as now"); + + Date r16 ("soy"); + t.ok (r16.sameYear (now), "eoy in same year as now"); + + // Date::sameHour + 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"); + t.ok (r17.sameHour (r18), "two dates within the same hour"); + + Date r19 ("6/7/2010 00:59:59", "m/d/Y H:N:S"); + t.notok (r17.sameHour (r19), "two dates not within the same hour"); // TODO Date::operator- }