diff options
author | Ken Murchison <murch@fastmail.com> | 2021-03-17 10:55:29 -0400 |
---|---|---|
committer | Ken Murchison <murch@fastmail.com> | 2021-03-21 08:53:58 -0400 |
commit | 67acb01508da92ccc7752df20e10dcfb420f1b1b (patch) | |
tree | 3f922d1a86c846b54e165ee0196a3b3bb9d0b472 | |
parent | b73df51675c373d854c7356b0b390f8e21fe5e61 (diff) | |
download | libical-git-67acb01508da92ccc7752df20e10dcfb420f1b1b.tar.gz |
icaltz-util.c: reorganize RRULE comparison for easier extensibility
-rw-r--r-- | src/libical/icaltz-util.c | 55 |
1 files changed, 35 insertions, 20 deletions
diff --git a/src/libical/icaltz-util.c b/src/libical/icaltz-util.c index 6f227110..4dccf7fa 100644 --- a/src/libical/icaltz-util.c +++ b/src/libical/icaltz-util.c @@ -714,6 +714,7 @@ icalcomponent *icaltzutil_fetch_timezone(const char *location) for (i = 1; i < num_trans; i++) { int last_trans = 0; + int terminate = 0; int by_day; time_t start; @@ -738,34 +739,48 @@ icalcomponent *icaltzutil_fetch_timezone(const char *location) zone = &standard; } - // Figure out if the rule has changed since the previous year - // If it has, update the recurrence rule of the current component and create a new component - // If it the current component was only valid for one year then remove the recurrence rule if (zone->rrule_comp) { - // Check if the pattern for daylight has changed - // If it has, create a new component and update UNTIL - // of previous component's RRULE - if (last_trans || - zone->recur.by_month[0] != icaltime.month || - zone->recur.by_day[0] != by_day || - types[prev_idx].gmtoff != zone->gmtoff_from || - zone->time.hour != icaltime.hour || - zone->time.minute != icaltime.minute || - zone->time.second != icaltime.second || - strcmp(types[idx].zname, zone->name)) { + if (last_trans) { + terminate = 1; + } + // Check if the zone name or the offset has changed + else if (types[prev_idx].gmtoff != zone->gmtoff_from || + strcmp(types[idx].zname, zone->name)) { + + terminate = 1; + } + // Check if most of the recurrence pattern is the same + else if (icaltime.month == zone->time.month && + icaltime.hour == zone->time.hour && + icaltime.minute == zone->time.minute && + icaltime.second == zone->time.second) { + + if (by_day != zone->recur.by_day[0]) { + // Different BYDAY + terminate = 1; + } + } + else { + // Different recurrence pattern entirely + terminate = 1; + } + if (terminate) { + // Terminate the current RRULE if (icaltime_compare(zone->time, zone->prev_time)) { + // Multiple instances // Set UNTIL of the previous component's recurrence - icaltime_adjust(&zone->time, 0, 0, 0, -types[prev_idx].gmtoff); + icaltime_adjust(&zone->time, + 0, 0, 0, -types[prev_idx].gmtoff); zone->time.zone = icaltimezone_get_utc_timezone(); - + zone->recur.until = zone->time; icalproperty_set_rrule(zone->rrule_prop, zone->recur); } else { - // Don't set UNTIL for a single instance - // Remove the RRULE - icalcomponent_remove_property(zone->rrule_comp, zone->rrule_prop); + // Remove the RRULE from the previous component + icalcomponent_remove_property(zone->rrule_comp, + zone->rrule_prop); icalproperty_free(zone->rrule_prop); } @@ -780,7 +795,7 @@ icalcomponent *icaltzutil_fetch_timezone(const char *location) if (!zone->rrule_comp) { zone->name = types[idx].zname; zone->prev_time = icaltime; - + zone->rrule_comp = icalcomponent_vanew(zone->kind, icalproperty_new_tzname(types[idx].zname), |