aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/cal-util/calobj.c
diff options
context:
space:
mode:
Diffstat (limited to 'calendar/cal-util/calobj.c')
-rw-r--r--calendar/cal-util/calobj.c164
1 files changed, 103 insertions, 61 deletions
diff --git a/calendar/cal-util/calobj.c b/calendar/cal-util/calobj.c
index 33aff8cda8..9e5f41bc27 100644
--- a/calendar/cal-util/calobj.c
+++ b/calendar/cal-util/calobj.c
@@ -1025,15 +1025,28 @@ generate (iCalObject *ico, time_t reference, calendarfn cb, void *closure)
e_t = mktime (&dt_end);
- if (s_t == -1 || e_t == -1){
+ if ((s_t == -1) || (e_t == -1)) {
g_warning ("Produced invalid dates!\n");
return 0;
}
- return (*cb)(ico, s_t, e_t, closure);
+
+ return (*cb) (ico, s_t, e_t, closure);
+}
+
+int
+ical_object_get_first_weekday (int weekday_mask)
+{
+ int i;
+
+ for (i = 0; i < 7; i++)
+ if (weekday_mask & (1 << i))
+ return i;
+
+ return -1;
}
-#define time_in_range(x,a,b) ((x >= a) && (b ? x <= b : 1))
-#define recur_in_range(t,r) (r->enddate ? (t < r->enddate) : 1)
+#define time_in_range(t, a, b) ((t >= a) && (b ? (t < b) : 1))
+#define recur_in_range(t, r) (r->enddate ? (t < r->enddate) : 1)
/*
* Generate every possible event. Invokes the callback routine for
@@ -1046,88 +1059,104 @@ generate (iCalObject *ico, time_t reference, calendarfn cb, void *closure)
void
ical_object_generate_events (iCalObject *ico, time_t start, time_t end, calendarfn cb, void *closure)
{
- Recurrence *recur = ico->recur;
time_t current;
- int first_week_day, i;
-
- if (!ico->recur){
- if ((end && (ico->dtstart < end) && ico->dtend > start) ||
- (end == 0 && ico->dtend > start)){
+ int first_week_day;
+
+ /* If there is no recurrence, just check ranges */
+
+ if (!ico->recur) {
+ if ((end && (ico->dtstart < end) && (ico->dtend > start))
+ || ((end == 0) && (ico->dtend > start))) {
time_t ev_s, ev_e;
- ev_s = ico->dtstart < start ? start : ico->dtstart;
- ev_e = ico->dtend > end ? end : ico->dtend;
- (*cb)(ico, ev_s, ev_e, closure);
+ /* Clip range */
+
+ ev_s = MAX (ico->dtstart, start);
+ ev_e = MIN (ico->dtend, end);
+
+ (* cb) (ico, ev_s, ev_e, closure);
}
return;
}
- /* The event has a recurrence rule */
- if (end != 0){
+ /* The event has a recurrence rule -- check that we will generate at least one instance */
+
+ if (end != 0) {
if (ico->dtstart > end)
return;
- if (!IS_INFINITE (recur) && recur->enddate < start)
+
+ if (!IS_INFINITE (ico->recur) && (ico->recur->enddate < start))
return;
}
+ /* Generate the instances */
+
current = ico->dtstart;
- switch (recur->type){
+
+ switch (ico->recur->type) {
case RECUR_DAILY:
do {
- if (time_in_range (current, start, end) && recur_in_range (current, recur)){
+ if (time_in_range (current, start, end) && recur_in_range (current, ico->recur))
if (!generate (ico, current, cb, closure))
return;
- }
/* Advance */
- current = time_add_day (current, recur->interval);
-
- if (current == -1){
- g_warning ("RECUR_DAILY: mktime error\n");
+
+ current = time_add_day (current, ico->recur->interval);
+
+ if (current == -1) {
+ g_warning ("RECUR_DAILY: time_add_day() returned invalid time");
return;
}
- } while (current < end || (end == 0));
+ } while ((current < end) || (end == 0));
+
break;
case RECUR_WEEKLY:
do {
- struct tm *tm = localtime (&current);
-
- if (time_in_range (current, start, end) && recur_in_range (current, recur)){
- if (recur->weekday & (1 << tm->tm_wday))
+ struct tm *tm;
+
+ tm = localtime (&current);
+
+ if (time_in_range (current, start, end) && recur_in_range (current, ico->recur)) {
+ /* Weekdays to recur on are specified as a bitmask */
+ if (ico->recur->weekday & (1 << tm->tm_wday))
if (!generate (ico, current, cb, closure))
return;
}
/* Advance by day for scanning the week or by interval at week end */
+
if (tm->tm_wday == 6)
- current = time_add_day (current, (recur->interval-1) * 7 + 1);
+ current = time_add_day (current, (ico->recur->interval - 1) * 7 + 1);
else
current = time_add_day (current, 1);
- if (current == -1){
- g_warning ("RECUR_WEEKLY: mktime error\n");
+ if (current == -1) {
+ g_warning ("RECUR_WEEKLY: time_add_day() returned invalid time\n");
return;
}
} while (current < end || (end == 0));
+
break;
-
+
case RECUR_MONTHLY_BY_POS:
/* FIXME: We only deal with positives now */
- if (recur->u.month_pos < 0)
+ if (ico->recur->u.month_pos < 0) {
+ g_warning ("RECUR_MONTHLY_BY_POS does not support negative positions yet");
return;
-
- if (recur->u.month_pos == 0)
+ }
+
+ if (ico->recur->u.month_pos == 0)
return;
-
- first_week_day = 7;
- for (i = 6; i >= 0; i--)
- if (recur->weekday & (1 << i))
- first_week_day = i;
+
+ first_week_day = ical_object_get_first_weekday (ico->recur->weekday);
/* This should not happen, but take it into account */
- if (first_week_day == 7)
+ if (first_week_day == -1) {
+ g_warning ("ical_object_get_first_weekday() returned -1");
return;
+ }
do {
struct tm tm;
@@ -1140,63 +1169,76 @@ ical_object_generate_events (iCalObject *ico, time_t start, time_t end, calendar
tm = *localtime (&t);
week_day_start = tm.tm_wday;
- tm.tm_mday = 7 * (recur->u.month_pos -
- ((week_day_start <= first_week_day ) ? 1 : 0)) -
- (week_day_start - first_week_day) + 1;
-
+ tm.tm_mday = (7 * (ico->recur->u.month_pos - ((week_day_start <= first_week_day ) ? 1 : 0))
+ - (week_day_start - first_week_day) + 1);
+
t = mktime (&tm);
-
- if (time_in_range (t, start, end) && recur_in_range (current, recur))
+
+ if (time_in_range (t, start, end) && recur_in_range (current, ico->recur))
if (!generate (ico, t, cb, closure))
return;
- /* Advance a month */
+ /* Advance by the appropriate number of months */
+
current = mktime (&tm);
tm.tm_mday = 1;
- tm.tm_mon += recur->interval;
+ tm.tm_mon += ico->recur->interval;
current = mktime (&tm);
- if (current == -1){
+ if (current == -1) {
g_warning ("RECUR_MONTHLY_BY_DAY: mktime error\n");
return;
}
- } while (current < end || (end == 0));
+ } while ((current < end) || (end == 0));
+
break;
case RECUR_MONTHLY_BY_DAY:
do {
- struct tm *tm = localtime (&current);
+ struct tm *tm;
time_t t;
int p;
+ tm = localtime (&current);
+
p = tm->tm_mday;
- tm->tm_mday = recur->u.month_day;
+ tm->tm_mday = ico->recur->u.month_day;
t = mktime (tm);
- if (time_in_range (t, start, end) && recur_in_range (current, recur))
+ if (time_in_range (t, start, end) && recur_in_range (current, ico->recur))
if (!generate (ico, t, cb, closure))
return;
- /* Advance a month */
+ /* Advance by the appropriate number of months */
+
tm->tm_mday = p;
- tm->tm_mon += recur->interval;
+ tm->tm_mon += ico->recur->interval;
current = mktime (tm);
- if (current == -1){
+
+ if (current == -1) {
g_warning ("RECUR_MONTHLY_BY_DAY: mktime error\n");
return;
}
} while (current < end || (end == 0));
+
+ break;
case RECUR_YEARLY_BY_MONTH:
case RECUR_YEARLY_BY_DAY:
do {
- if (time_in_range (current, start, end) && recur_in_range (current, recur))
+ if (time_in_range (current, start, end) && recur_in_range (current, ico->recur))
if (!generate (ico, current, cb, closure))
return;
-
+
/* Advance */
- current = time_add_year (current, recur->interval);
+
+ current = time_add_year (current, ico->recur->interval);
} while (current < end || (end == 0));
+
+ break;
+
+ default:
+ g_assert_not_reached ();
}
}
@@ -1210,7 +1252,7 @@ duration_callback (iCalObject *ico, time_t start, time_t end, void *closure)
(*count)++;
if (ico->recur->duration == *count) {
- ico->recur->enddate = time_end_of_day (end);
+ ico->recur->enddate = time_day_end (end);
return 0;
}
return 1;
mmit/deskutils?id=d9f40b85c79468d4a67e2e1a6660c012d9380d99'>AppWrapper is a GNUstep application meant to aid in the creation ofdinoex2006-12-165-0/+54 * Fix a double-free while performing print operations which could trigger aahze2006-12-166-0/+81 * Update to version 2.7markus2006-12-154-8/+8 * - Update to 1.4.1miwi2006-12-142-4/+4 * - Update to 7.8.3sat2006-12-142-4/+4 * Update the ftp/curl port to 7.16.0.roam2006-12-134-8/+8 * - Fix pkg-plistrafan2006-12-111-0/+3 * - Respect X11BASErafan2006-12-111-3/+25 * Chase Xapian's upgrade.thierry2006-12-101-1/+2 * - Update to 1.6.3rafan2006-12-093-6/+7 * - Update to 5.1.2miwi2006-12-092-7/+7 * Add pinot 0.64, personal search and metasearch for the Free Desktop.thierry2006-12-085-0/+169 * Add a missing dependency on desktopfileutils, and update the desktopmarcus2006-12-072-1/+7 * Remove expired ports:vd2006-12-042-18/+0 * Katapult is a KDE application that gives you faster access toitetcu2006-12-035-0/+139 * Update WWW.marcus2006-12-021-1/+1 * Update to 0.14.2.marcus2006-12-023-47/+94 * Upgrade to 2.1.4.shaun2006-12-029-21/+30 * - Use features of bsd.wx.mk, especially USE_WXpav2006-12-011-2/+2 * - add missing includedinoex2006-12-012-5/+10 * - pass X11BASEdinoex2006-12-011-4/+5 * - Update to 0.2miwi2006-11-304-52/+10 * - Update to 1.10pav2006-11-303-11/+12 * Respect the X11BASE and the CC settings.mi2006-11-301-0/+2 * Update to 0.11.tobez2006-11-282-4/+4 * - fix linker pathsdinoex2006-11-282-7/+10 * - pass LDFLAGS to Makefiledinoex2006-11-271-0/+1 * MenuServer - the server app which provides the menubar'sdinoex2006-11-255-0/+96 * Upgrade to version 1.9.7.olgeni2006-11-233-7/+26 * - Update to 1.5.11miwi2006-11-222-4/+4 * Update master site.ehaupt2006-11-2111-11/+11 * - fix pkg-plist, addresses http://pointyhat.freebsd.org/errorlogs/i386-errorl...clsung2006-11-212-23/+21 * - Update to 0.6.5miwi2006-11-214-10/+24 * - Update to 2.16.2ahze2006-11-214-6/+7 * - Camaelon and WildMenus have beenn moved out into seperate portsdinoex2006-11-206-26/+6 * Etoile intends to be an innovative GNUstep based user environnement builtdinoex2006-11-205-0/+80 * Etoile intends to be an innovative GNUstep based user environnement builtdinoex2006-11-205-0/+120 * Etoile intends to be an innovative GNUstep based user environnement builtdinoex2006-11-205-0/+55 * Etoile intends to be an innovative GNUstep based user environnement builtdinoex2006-11-205-0/+62 * Etoile intends to be an innovative GNUstep based user environnement builtdinoex2006-11-205-0/+49 * Etoile intends to be an innovative GNUstep based user environnement builtdinoex2006-11-205-0/+72 * - fix COMMENTdinoex2006-11-191-1/+1 * PreferencesKit is a framework which provides various features to builddinoex2006-11-195-0/+79 * Etoile intends to be an innovative GNUstep based user environnement builtdinoex2006-11-195-0/+65 * - cleanup pkg-plistdinoex2006-11-191-1/+1 * Add lightning-xpiahze2006-11-184-0/+70 * PlopFolio is a free clone of Serence's excellent KlipFolio application.dinoex2006-11-175-0/+66 * - update to 0.2alexbl2006-11-172-4/+4 * * Make the gmime dependency default [1]marcus2006-11-172-15/+9 * GNUWash is a configurable GNUstep timer application.dinoex2006-11-175-0/+55 * GNUstepWrapper provides an easy way to create GNUstep app-wrappers ofdinoex2006-11-175-0/+63 * DisplayCalibrator - Frontend to xgammadinoex2006-11-175-0/+47 * Fix the packing listjylefort2006-11-161-0/+1 * - Update to 0.35.4miwi2006-11-167-22/+33 * - Update to 0.9.9sat2006-11-153-11/+8 * fix configure stepoliver2006-11-151-1/+4 * - Update to 0.3.6jylefort2006-11-144-66/+25 * Track libnotify updatejylefort2006-11-142-3/+3 * - add TagFu 0.1alexbl2006-11-145-0/+44 * - fix pkg-plist, addresses http://pointyhat.freebsd.org/errorlogs/i386-errorl...clsung2006-11-142-13/+11 * - Update to 13.3rafan2006-11-132-5/+6 * dbh got updated some time agooliver2006-11-131-2/+2 * - Install icons and flagsmiwi2006-11-132-0/+89 * Reset inactive maintainer asa@gascom.ru.linimon2006-11-131-1/+1 * - Update to 7.8.2sat2006-11-122-4/+4 * Remove expired ports:vd2006-11-094-52/+0 * Change my email address to farrokhi@ in all ports that I maintain.farrokhi2006-11-081-1/+1 * - Fix pkg-plist.alepulver2006-11-072-13/+10 * Update to 2.16.2ahze2006-11-063-4/+13 * Etoile intends to be an innovative GNUstep based user environnement builtdinoex2006-11-059-0/+141 * Add USE_GETTEXT.mezz2006-11-051-0/+1 * INSTALLS_SHLIB -> USE_LDCONFIG.mezz2006-11-052-2/+2 * Update to 0.8.2.mezz2006-11-044-24/+10 * Drop maintainershipjylefort2006-11-031-1/+1 * - Update to 7.8sat2006-11-022-4/+4 * - Fix MASTER_SITESmiwi2006-11-011-1/+1 * - Update to 13.2rafan2006-11-012-5/+4 * SugarCRM like to move their source files around the place for no apparentclsung2006-11-011-1/+1 * deskutils/phpicalendar has undeclared dependency on www/php5-session portedwin2006-11-011-1/+1 * - Update to 7.7.7 (Jackpot!)sat2006-11-013-27/+31 * - Update to version 0.6.0markus2006-11-013-29/+130 * This is a GkrellM2 plugin that allows setting of various countdown timersalepulver2006-11-014-0/+41 * Remove expired leaf ports:vd2006-10-316-77/+0 * - Update to 0.8.3miwi2006-10-312-4/+4 * - Fix depends with py-libxml2miwi2006-10-311-0/+2 * NoteBook.app is an application to store and organize your notes writtendinoex2006-10-315-0/+66 * HelpViewer is an online help viewer for GNUstep programsdinoex2006-10-315-0/+72 * System Preferences is a clone of the Apple OS X System Preferencesdinoex2006-10-315-0/+112 * NSPreferencePane is an abstract class that defines the interface fordinoex2006-10-315-0/+53 * Affiche is a little application that allows people to "stick"dinoex2006-10-315-0/+71 * - clean package namedinoex2006-10-311-2/+2 * - drop USE_X_PREFIXdinoex2006-10-311-1/+1 * Update to 2.16.1 to fix several of crash bugs.mezz2006-10-242-5/+4 * Attempt to remove share/pixmaps.marcus2006-10-202-1/+2 * Fix crash due to DllImport of non-existant function in libc.tmclaugh2006-10-192-0/+28 * Add an alternate download site since the main site is temporarily down.marcus2006-10-161-1/+2 * - Fix dependsahze2006-10-151-1/+1 * Fix the version numbers going backwards by add PORTEPOCH.mezz2006-10-153-0/+3 * Add akamaru, a physics engine prototype.marcus2006-10-147-0/+103 * - Add ontvahze2006-10-148-0/+179 * - Add conduitahze2006-10-146-0/+163 * Chase the GNOME X11BASE to LOCALBASE move, and fix the build with themarcus2006-10-14