aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Henriksen <LarsHenriksen@get2net.dk>2019-04-27 23:28:52 +0200
committerLukas Fleischer <lfleischer@calcurse.org>2019-05-20 09:37:11 -0400
commit2be32c4bda5236ec19e0f3c544adcd2974684f50 (patch)
treee7a58d113e3562a5e8227af9a60897444c3cc20a
parent8741334d83aa5f77f1169af70493f394f860779f (diff)
downloadcalcurse-2be32c4bda5236ec19e0f3c544adcd2974684f50.tar.gz
calcurse-2be32c4bda5236ec19e0f3c544adcd2974684f50.zip
Impossible dates in recurrence rules
According to RFC 5545 dates like 30 February and 31 June must be ignored when derived from a recurrence rule. calcurse relies on mktime() "normalization" of dates (e.g. turning 32 December 2019 into 1 January 2020 when moving from 31 December to the next day). Normalization may also lead to impossible dates in monthly and yearly recurrence rules, and this must be avoided. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
-rw-r--r--src/recur.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/recur.c b/src/recur.c
index 4e8bd09..46f669d 100644
--- a/src/recur.c
+++ b/src/recur.c
@@ -815,6 +815,18 @@ recur_item_find_occurrence(time_t item_start, long item_dur,
lt_item_day.tm_isdst = lt_day.tm_isdst;
t = mktime(&lt_item_day);
+ /*
+ * Impossible dates must be ignored (according to RFC 5545). Changing
+ * only the year or the month may lead to dates like 29 February in
+ * non-leap years or 31 November.
+ */
+ if (rpt_type == RECUR_MONTHLY || rpt_type == RECUR_YEARLY) {
+ localtime_r(&t, &lt_item_day);
+ if (lt_item_day.tm_mday != lt_item.tm_mday)
+ return 0;
+ }
+
+ /* Exception day? */
if (LLIST_FIND_FIRST(item_exc, &t, exc_inday))
return 0;