From 9099a353eaa463416f3dc526994491022ced4747 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 6 Oct 2013 15:30:35 -0400 Subject: [PATCH] Bug #1286 - #1286 Cannot use "sow", "som", etc in "entry.after", "end.after" filters (thanks to Jake Bell). --- ChangeLog | 2 ++ src/Date.cpp | 28 +++++++++++++++++++++++----- test/date.t.cpp | 4 ++-- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index a22adfe96..c581984d1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -70,6 +70,8 @@ Bugs + #1270 The 'undo' command is now properly removing backlog entries. + #1279 Assorted corrections to the task-ref.pdf document (thanks to Benjamin Weber). + + #1286 Cannot use "sow", "som", etc in "entry.after", "end.after" filters + (thanks to Jake Bell). + #1300 Encode/decode pairing is now properly balanced. + #1305 Commit hash now available in tarball builds (thanks to Ben Boeckel). + #1352 Terminal crashes when using taskwarrior's zsh completion (thanks to diff --git a/src/Date.cpp b/src/Date.cpp index 829cab59a..c7400a657 100644 --- a/src/Date.cpp +++ b/src/Date.cpp @@ -853,8 +853,7 @@ bool Date::isRelativeDate (const std::string& input) found == "eoww" || found == "eocw" || found == "sow" || - found == "soww" || - found == "socw") + found == "soww") { if (found == "eow" || found == "eoww") dow = 5; @@ -865,9 +864,6 @@ bool Date::isRelativeDate (const std::string& input) if (found == "sow" || found == "soww") dow = 1; - if (found == "socw") - dow = Date::dayOfWeek (context.config.get ("weekstart")); - if (today.dayOfWeek () >= dow) today += (dow - today.dayOfWeek () + 7) * 86400; else @@ -880,6 +876,28 @@ bool Date::isRelativeDate (const std::string& input) _t = then._t; return true; } + + else if (found == "socw") + { + // day S M T W T F S + // dow 0 1 2 3 4 5 6 + // ----------------------- + // weekstart ^ + // today1 ^ + // today2 ^ + // + // delta1 = 6 <-- (0 - 1 + 7) % 7 + // delta2 = 3 <-- (4 - 1 + 7) % 7 + + dow = Date::dayOfWeek (context.config.get ("weekstart")); + int delta = (today.dayOfWeek () - dow + 7) % 7; + today -= delta * 86400; + + Date then (today.month (), today.day (), today.year ()); + _t = then._t; + return true; + } + else if (found == "today") { Date then (today.month (), diff --git a/test/date.t.cpp b/test/date.t.cpp index 42ec59cac..e21adbf77 100644 --- a/test/date.t.cpp +++ b/test/date.t.cpp @@ -337,7 +337,7 @@ int main (int argc, char** argv) t.ok (r11 < now + (8 * 86400), "eow < 7 days away"); Date r12 ("eocw"); - t.ok (r12 < now + (8 * 86400), "eocw < 7 days away"); + t.ok (r12 > now - (8 * 86400), "eocw < 7 days in the past"); Date r13 ("eom"); t.ok (r13.sameMonth (now), "eom in same month as now"); @@ -352,7 +352,7 @@ int main (int argc, char** argv) t.ok (r16 < now + (8 * 86400), "sow < 7 days away"); Date r23 ("socw"); - t.ok (r23 < now + (8 * 86400), "sow < 7 days away"); + t.ok (r23 > now - (8 * 86400), "sow < 7 days in the past"); Date r17 ("som"); t.notok (r17.sameMonth (now), "som not in same month as now");