Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

guesstz.c: support both icalrecur by ref and by value #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ AC_INIT([cyrus-timezones],[1.0])
AC_CANONICAL_TARGET
AM_INIT_AUTOMAKE
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_HEADERS(config.h)

dnl Checks for programs.
AC_PROG_CC
Expand All @@ -29,7 +30,12 @@ dnl AC_FUNC_VPRINTF
dnl AC_CHECK_FUNCS([gettimeofday memset strchr strdup strpbrk])

dnl Checks for required libraries
PKG_CHECK_MODULES([ICAL], [libical])
PKG_CHECK_MODULES([ICAL], [libical], [
dnl icalrecurrencetype_new will be new in libical 4.0
AC_CHECK_LIB(ical, icalrecurrencetype_new,
AC_DEFINE(HAVE_RECUR_BY_REF,[],
[Do we have support for icalrecurrencetype by reference?]))
])
AC_SUBST([ICAL_LIBS])
AC_SUBST([ICAL_CFLAGS])
PKG_CHECK_VAR([ICAL_LIBDIR], [libical], [libdir])
Expand Down
26 changes: 17 additions & 9 deletions guesstz/guesstz.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#include <jansson.h>
#include <libical/ical.h>

#include "config.h"
#include "guesstz.h"

/*
Expand Down Expand Up @@ -391,17 +392,24 @@ static void expand_icalobservances(icalcomponent *vtz,
}

if (rrule_prop) {
#ifdef HAVE_RECUR_BY_REF
struct icalrecurrencetype *rrule =
icalproperty_get_rrule(rrule_prop);
icaltimetype *rrule_until = &rrule->until;
#else
struct icalrecurrencetype rrule =
icalproperty_get_rrule(rrule_prop);
icaltimetype *rrule_until = &rrule.until;
#endif
icalrecur_iterator *ritr = NULL;
unsigned eternal = icaltime_is_null_time(rrule.until);
unsigned eternal = icaltime_is_null_time(*rrule_until);
unsigned trunc_until = 0;

/* Check RRULE duration */
if (!eternal && icaltime_compare(rrule.until, start) < 0) {
if (!eternal && icaltime_compare(*rrule_until, start) < 0) {
/* RRULE ends prior to our window open -
check UNTIL vs tombstone */
obs.onset = rrule.until;
obs.onset = *rrule_until;
if (need_tomb) check_tombstone(&tombstone, &obs);

/* Remove RRULE */
Expand All @@ -411,15 +419,15 @@ static void expand_icalobservances(icalcomponent *vtz,
else {
/* RRULE ends on/after our window open */
if (!icaltime_is_null_time(end) &&
(eternal || icaltime_compare(rrule.until, end) >= 0)) {
(eternal || icaltime_compare(*rrule_until, end) >= 0)) {
/* RRULE ends after our window close - need to adjust it */
trunc_until = 1;
}

if (!eternal) {
/* Adjust UNTIL to local time (for iterator) */
icaltime_adjust(&rrule.until, 0, 0, 0, obs.offset_from);
icaltime_set_utc(&rrule.until, 0);
icaltime_adjust(rrule_until, 0, 0, 0, obs.offset_from);
icaltime_set_utc(rrule_until, 0);
}

if (trunc_dtstart) {
Expand Down Expand Up @@ -470,7 +478,7 @@ static void expand_icalobservances(icalcomponent *vtz,
}
else if (!eternal) {
/* Set UNTIL to previous onset */
rrule.until = prev_onset;
*rrule_until = prev_onset;
icalproperty_set_rrule(rrule_prop, rrule);
}

Expand All @@ -496,7 +504,7 @@ static void expand_icalobservances(icalcomponent *vtz,
trunc_dtstart = 0;

/* Check if new DSTART is within 1yr of UNTIL */
ydiff = rrule.until.year - recur.year;
ydiff = rrule_until->year - recur.year;
if (!trunc_until && ydiff <= 1) {
/* Remove RRULE */
icalcomponent_remove_property(comp, rrule_prop);
Expand All @@ -505,7 +513,7 @@ static void expand_icalobservances(icalcomponent *vtz,
if (ydiff) {
/* Add UNTIL as RDATE */
struct icaldatetimeperiodtype rdate = {
rrule.until,
*rrule_until,
icalperiodtype_null_period()
};
prop = icalproperty_new_rdate(rdate);
Expand Down