From 2be32c4bda5236ec19e0f3c544adcd2974684f50 Mon Sep 17 00:00:00 2001 From: Lars Henriksen Date: Sat, 27 Apr 2019 23:28:52 +0200 Subject: 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 Signed-off-by: Lukas Fleischer --- src/recur.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src') 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(<_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, <_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; -- cgit v1.2.3-70-g09d2