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>
This commit is contained in:
Lars Henriksen 2019-04-27 23:28:52 +02:00 committed by Lukas Fleischer
parent 8741334d83
commit 2be32c4bda

View File

@ -815,6 +815,18 @@ recur_item_find_occurrence(time_t item_start, long item_dur,
lt_item_day.tm_isdst = lt_day.tm_isdst; lt_item_day.tm_isdst = lt_day.tm_isdst;
t = mktime(&lt_item_day); 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)) if (LLIST_FIND_FIRST(item_exc, &t, exc_inday))
return 0; return 0;