From bc41e7378a3765d0cb29c7b04dbe93a3418ff1c9 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Mon, 26 Aug 2013 09:25:29 -0700 Subject: [PATCH] Feature - New virtual tags (WEEK, MONTH, YEAR, PARENT). --- ChangeLog | 3 +- NEWS | 1 + doc/man/task.1.in | 4 +++ src/Task.cpp | 71 +++++++++++++++++++++++++++++++++++++++++++---- src/Task.h | 3 ++ 5 files changed, 76 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index a32f238e3..c6ba9c8ba 100644 --- a/ChangeLog +++ b/ChangeLog @@ -36,6 +36,7 @@ Features specifying \uNNNN. + Now requires libuuid (thanks to Martin Natano). + New '_get' is a DOM accessor helper command. + + New virtual tags (WEEK, MONTH, YEAR, PARENT). Bugs + #1196 Now builds on Hurd (thanks to Jakub Wilk). @@ -89,7 +90,7 @@ Features + Removed deprecated 'fg:' and 'bg:' attributes. + The 'diagnostics' command now reports libuuid details. + New characters for parsing and formating dates ('n', 's' and 'v'). - + Virtual tags (BLOCKED, UNBLOCKED, BLOCKING, DUE, DUETODAY, TODAY, OVERDUE, + + Virtual tags (BLOCKED, UNBLOCKED, BLOCKING, DUE, DUETODAY, OVERDUE, TODAY, ACTIVE, SCHEDULED, CHILD, UNTIL, WAITING and ANNOTATED). + New 'modified' attribute, which contains the most recent modification date, if a modification has occurred. diff --git a/NEWS b/NEWS index 4a3d7e324..7b11d1189 100644 --- a/NEWS +++ b/NEWS @@ -8,6 +8,7 @@ New Features in taskwarrior 2.3.0 - UDA fields now allow default values. - Now requires libuuid. - New '_get' DOM accessor helper command. + - New virtual tags: WEEK, MONTH, YEAR, PARENT. New commands in taskwarrior 2.3.0 diff --git a/doc/man/task.1.in b/doc/man/task.1.in index feedb78dc..db69dafc7 100644 --- a/doc/man/task.1.in +++ b/doc/man/task.1.in @@ -588,9 +588,13 @@ are: DUE Matches if the task is due DUETODAY Matches if the task is due today TODAY Matches if the task is due today + WEEK Matches if the task is due this week + MONTH Matches if the task is due this month + YEAR Matches if the task is due this year OVERDUE Matches if the task is overdue ACTIVE Matches if the task is started SCHEDULED Matches if the task is scheduled + PARENT Matches if the task is a parent CHILD Matches if the task has a parent UNTIL Matches if the task expires WAITING Matches if the task is waiting diff --git a/src/Task.cpp b/src/Task.cpp index 4de6055c7..3ff4ccfe4 100644 --- a/src/Task.cpp +++ b/src/Task.cpp @@ -361,6 +361,68 @@ bool Task::is_duetoday () const return false; } +//////////////////////////////////////////////////////////////////////////////// +bool Task::is_dueweek () const +{ + if (has ("due")) + { + Task::status status = getStatus (); + + if (status != Task::completed && + status != Task::deleted) + { + Date now; + Date due (get_date ("due")); + if (now.year () == due.year () && + now.week () == due.week ()) + return true; + } + } + + return false; +} + +//////////////////////////////////////////////////////////////////////////////// +bool Task::is_duemonth () const +{ + if (has ("due")) + { + Task::status status = getStatus (); + + if (status != Task::completed && + status != Task::deleted) + { + Date now; + Date due (get_date ("due")); + if (now.year () == due.year () && + now.month () == due.month ()) + return true; + } + } + + return false; +} + +//////////////////////////////////////////////////////////////////////////////// +bool Task::is_dueyear () const +{ + if (has ("due")) + { + Task::status status = getStatus (); + + if (status != Task::completed && + status != Task::deleted) + { + Date now; + Date due (get_date ("due")); + if (now.year () == due.year ()) + return true; + } + } + + return false; +} + //////////////////////////////////////////////////////////////////////////////// bool Task::is_overdue () const { @@ -1026,6 +1088,9 @@ bool Task::hasTag (const std::string& tag) const if (tag == "DUETODAY") return is_duetoday (); if (tag == "TODAY") return is_duetoday (); if (tag == "OVERDUE") return is_overdue (); + if (tag == "WEEK") return is_dueweek (); + if (tag == "MONTH") return is_duemonth (); + if (tag == "YEAR") return is_dueyear (); #endif if (tag == "ACTIVE") return has ("start"); if (tag == "SCHEDULED") return has ("scheduled"); @@ -1033,16 +1098,12 @@ bool Task::hasTag (const std::string& tag) const if (tag == "UNTIL") return has ("until"); if (tag == "WAITING") return has ("wait"); if (tag == "ANNOTATED") return hasAnnotations (); + if (tag == "PARENT") return has ("mask"); /* TODO YESTERDAY - due yesterday TODO TOMORROW - due tomorrow - TODO WEEK - due this week - TODO MONTH - due this month - TODO YEAR - due this year TODO READY - is ready - TODO WAITING - is waiting - TODO PARENT - is a parent */ // Concrete tags. diff --git a/src/Task.h b/src/Task.h index 5fcb8525b..c322fc29c 100644 --- a/src/Task.h +++ b/src/Task.h @@ -106,6 +106,9 @@ public: #ifdef PRODUCT_TASKWARRIOR bool is_due () const; bool is_duetoday () const; + bool is_dueweek () const; + bool is_duemonth () const; + bool is_dueyear () const; bool is_overdue () const; #endif