libical r648 - in branches/gnome-2-22: . src/libical



Author: pchen
Date: Mon Sep  1 08:58:48 2008
New Revision: 648
URL: http://svn.gnome.org/viewvc/libical?rev=648&view=rev

Log:
Fixes #548268.




Modified:
   branches/gnome-2-22/ChangeLog
   branches/gnome-2-22/src/libical/icaltz-util.c

Modified: branches/gnome-2-22/src/libical/icaltz-util.c
==============================================================================
--- branches/gnome-2-22/src/libical/icaltz-util.c	(original)
+++ branches/gnome-2-22/src/libical/icaltz-util.c	Mon Sep  1 08:58:48 2008
@@ -198,6 +198,21 @@
 	return zdir;
 }
 
+/* Calculate the relative position of the week in a month from a date */
+static int
+calculate_pos (icaltimetype icaltime)
+{
+	int pos;
+
+	pos = (icaltime.day -1) / 7;
+
+	/* Check if pos 3 is the last occurence of the week day in the month */	
+	if (pos == 3 && ((icaltime.day + 7) > icaltime_days_in_month (icaltime.month, icaltime.year))) 
+		pos = 4;
+
+	return r_pos [pos];
+}
+
 icalcomponent*
 icaltzutil_fetch_timezone (const char *location)
 {
@@ -349,7 +364,7 @@
 			icalrecurrencetype_clear (&ical_recur);
 			ical_recur.freq = ICAL_YEARLY_RECURRENCE;
 			ical_recur.by_month [0] = icaltime.month;
-			pos = r_pos [icaltime.day/7];
+			pos = calculate_pos (icaltime);
 			pos < 0 ? (sign = -1): (sign = 1);
 			ical_recur.by_day [0] = sign * ((abs (pos) * 8) + icaltime_day_of_week (icaltime));
 			icalprop = icalproperty_new_rrule (ical_recur);
@@ -387,7 +402,7 @@
 		icalrecurrencetype_clear (&ical_recur);
 		ical_recur.freq = ICAL_YEARLY_RECURRENCE;
 		ical_recur.by_month [0] = icaltime.month;
-		pos = r_pos [icaltime.day/7];
+		pos = calculate_pos (icaltime);
 		pos < 0 ? (sign = -1): (sign = 1);
 		ical_recur.by_day [0] = sign * ((abs (pos) * 8) + icaltime_day_of_week (icaltime));
 		icalprop = icalproperty_new_rrule (ical_recur);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]