Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Patch for TW-13 in Taskwarrior
$ Patch for daylight savings time
--- src/recur.cpp.orig
+++ src/recur.cpp
@@ -215,6 +215,7 @@ ISO8601d getNextRecurrence (ISO8601d& current, std::string& period)
int m = current.month ();
int d = current.day ();
int y = current.year ();
+ ISO8601d recurrence_date;
// Some periods are difficult, because they can be vague.
if (period == "monthly" ||
@@ -240,8 +241,10 @@ ISO8601d getNextRecurrence (ISO8601d& current, std::string& period)
if (dow == 5) days = 3;
else if (dow == 6) days = 2;
else days = 1;
-
- return current + (days * 86400);
+ // Shift current to midday to be safe of any DST changes, before calculating future date
+ recurrence_date = (ISO8601d (m, d, y) + 43200) + (days * 86400);
+ // Then set back to correct hour
+ return ISO8601d(recurrence_date.month (), recurrence_date.day (), recurrence_date.year ()) + 3600 * current.hour () + 60 * current.minute() + current.second ();
}
else if (Lexer::isDigit (period[0]) &&
@@ -379,3 +382,13 @@ ISO8601d getNextRecurrence (ISO8601d& current, std::string& period)
secs = (time_t) p;
+ // if period is daily or greater, and a whole number of days, do the same as per weekdays
+ if ((secs >= 86400) && (secs % 86400 == 0))
+ {
+ // Shift current to midday to be safe of any DST changes, before calculating future date
+ recurrence_date = (ISO8601d (m, d, y) + 43200) + secs;
+ // Then set back to correct hour
+ return ISO8601d (recurrence_date.month (), recurrence_date.day (), recurrence_date.year ()) + 3600 * current.hour () + 60 * current.minute() + current.second ();
+ // Note: there are some edge cases where this still doesn't work for reasons unknown.
+ // However, it is safe for the default task times of midnight
+ }
return current + secs;
}
@atomicules
Copy link
Author

atomicules commented Dec 19, 2015

See original revision for more comments (that were in the git format patch). I keep this as a local patch for Pkgsrc now so I've removed all the original comments, etc. Current patch is for 2.5.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment