diff --git a/SOPE/NGCards/ChangeLog b/SOPE/NGCards/ChangeLog index 5452a8c1c..8e3f530ed 100644 --- a/SOPE/NGCards/ChangeLog +++ b/SOPE/NGCards/ChangeLog @@ -1,3 +1,9 @@ +2010-10-18 Wolfgang Sourdeau + + * iCalTimeZonePeriod.m (_occurenceForDate:byRRule:): we don't need + to deduct the offset from UTC from the resulting date since + "tzStart" is already relative to UTC. + 2010-10-13 Francis Lachapelle * NSString+NGCards.m (-vCardSubvaluesWithSeparator): properly diff --git a/SOPE/NGCards/iCalTimeZonePeriod.m b/SOPE/NGCards/iCalTimeZonePeriod.m index 598e83282..512c1a551 100644 --- a/SOPE/NGCards/iCalTimeZonePeriod.m +++ b/SOPE/NGCards/iCalTimeZonePeriod.m @@ -145,14 +145,13 @@ timeZone: [NSTimeZone timeZoneWithName: @"GMT"]]; tmpDate = [tmpDate addYear: 0 month: ((pos > 0) ? 0 : 1) day: 0 hour: 0 minute: 0 - second: -[self _secondsOfOffset: @"tzoffsetfrom"]]; + second: 0]; - dateDayOfWeek = [tmpDate dayOfWeek]; - /* If the day of the time change is "-XSU", we need to determine whether the first day of next month is in the same week. In practice, as most time changes occurs on sundays, it will be false only when that first day is a sunday, but we want to remain algorithmically exact. */ + dateDayOfWeek = [tmpDate dayOfWeek]; if (dateDayOfWeek > dayOfWeek && pos < 0) pos++; diff --git a/Tests/Unit/TestiCalTimeZonePeriod.m b/Tests/Unit/TestiCalTimeZonePeriod.m index 09657ea9c..eee42ab8e 100644 --- a/Tests/Unit/TestiCalTimeZonePeriod.m +++ b/Tests/Unit/TestiCalTimeZonePeriod.m @@ -42,6 +42,47 @@ @implementation TestiCalTimeZonePeriod +- (void) test_occurenceForDate_ +{ + NSString *periods[] = { (@"BEGIN:DAYLIGHT\r\n" + @"TZOFFSETFROM:-0500\r\n" + @"TZOFFSETTO:-0400\r\n" + @"TZNAME:EDT\r\n" + @"DTSTART:19700308T020000\r\n" + @"RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU\r\n" + @"END:DAYLIGHT"), + (@"BEGIN:STANDARD\r\n" + @"TZOFFSETFROM:-0400\r\n" + @"TZOFFSETTO:-0500\r\n" + @"TZNAME:EST\r\n" + @"DTSTART:19701101T020000\r\n" + @"RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=1SU\r\n" + @"END:STANDARD") }; + NSString *dateStrings[] = { @"20100314T050000Z", @"20101107T050000Z" }; + // with TZ=America/Montreal: + // date --date="2010-03-14 01:59" +"%s" -> 1268549940 + // date --date="2010-03-14 02:00" +"%s" -> invalid + // date --date="2010-03-14 03:00" +"%s" -> 1268550000 + // date --date="2010-11-07 01:59" +"%s" -> 1289109540 + // date --date="2010-11-07 02:00" +"%s" -> 1289113200 + NSInteger occurrenceSeconds[] = { 1268550000, 1289113200 }; + NSInteger count, delta; + iCalTimeZonePeriod *period; + NSCalendarDate *testDate; + + for (count = 0; count < 2; count++) + { + period = [iCalTimeZonePeriod parseSingleFromSource: periods[count]]; + testDate = [period occurenceForDate: [dateStrings[count] asCalendarDate]]; + delta = (NSInteger) [testDate timeIntervalSince1970] - occurrenceSeconds[count]; + testWithMessage ((NSInteger) [testDate timeIntervalSince1970] + == occurrenceSeconds[count], + ([NSString stringWithFormat: + @"test %d: seconds do not match:" + @" delta = %d", count, delta])); + } +} + - (void) test__occurenceForDate_byRRule_ { /* all rules are happening on 2010-03-14 */