From 6484ed17fe51db02540e3f56a52528a856a217a6 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Mon, 18 Oct 2010 23:12:04 +0000 Subject: [PATCH] Monotone-Parent: 006880968b9bb9ad30735d48958c2b1ad1396bce Monotone-Revision: 09e07a1c8e00beee8c2f4bdeebb726ac5f57b9e9 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2010-10-18T23:12:04 Monotone-Branch: ca.inverse.sogo --- SOPE/NGCards/ChangeLog | 6 +++++ SOPE/NGCards/iCalTimeZonePeriod.m | 5 ++-- Tests/Unit/TestiCalTimeZonePeriod.m | 41 +++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 3 deletions(-) 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 */