From cd64ca199a9846d9dc9a36a99fac39285303b9c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrique=20J=2E=20Hern=C3=A1ndez=20Blasco?= Date: Thu, 16 Oct 2014 16:11:43 +0200 Subject: [PATCH] oc-calendar: wDay field cannot be negative Furthermore, [MS-OXOCAL] Section 2.2.1.41.1 indicates: The wDay field is set to indicate the occurrence of the day of the week within the month (1 to 5, where 5 indicates the final occurrence during the month if that day of the week does not occur 5 times). [rule firstOccurrence] may return negative values according to iCal spec for recurrent rules iCal 4.8.5.4 Recurrence Rule. For instance, for defining a timezone whose recurrent rule is done using this rule: RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU This fixes the problem when editing a recurrent appointment in Outlook were incorrectly shifted when SOGo provides back the event. --- OpenChange/iCalTimeZone+MAPIStore.m | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/OpenChange/iCalTimeZone+MAPIStore.m b/OpenChange/iCalTimeZone+MAPIStore.m index 8e9bf7c14..f692272db 100644 --- a/OpenChange/iCalTimeZone+MAPIStore.m +++ b/OpenChange/iCalTimeZone+MAPIStore.m @@ -51,6 +51,7 @@ NSArray *byMonth; iCalByDayMask *mask; NSCalendarDate *dateValue; + int16_t wDay; rrule = [self recurrenceRule]; byMonth = [rrule byMonth]; @@ -59,7 +60,14 @@ tzData->wMonth = [[byMonth objectAtIndex: 0] intValue]; mask = [rrule byDayMask]; tzData->wDayOfWeek = [mask firstDay]; - tzData->wDay = [mask firstOccurrence]; + wDay = [mask firstOccurrence]; + if (wDay < 0) + /* [MS-OXOCAL] the wDay field is set to indicate the + occurrence of the day of the week within the month (1 to + 5, where 5 indicates the final occurrence during the + month if that day of the week does not occur 5 times). */ + wDay += 6; + tzData->wDay = (uint16_t) wDay; dateValue = [self startDate]; tzData->wHour = [dateValue hourOfDay];