[CalendarServer-changes] [13135] PyCalendar/trunk/src/pycalendar

source_changes at macosforge.org source_changes at macosforge.org
Wed Apr 2 17:42:33 PDT 2014


Revision: 13135
          http://trac.calendarserver.org//changeset/13135
Author:   cdaboo at apple.com
Date:     2014-04-02 17:42:33 -0700 (Wed, 02 Apr 2014)
Log Message:
-----------
Make sure converting from one timezone to another works correctly near a DST change.

Modified Paths:
--------------
    PyCalendar/trunk/src/pycalendar/datetime.py
    PyCalendar/trunk/src/pycalendar/icalendar/calendar.py
    PyCalendar/trunk/src/pycalendar/icalendar/tests/test_timezone.py
    PyCalendar/trunk/src/pycalendar/icalendar/vtimezone.py
    PyCalendar/trunk/src/pycalendar/timezone.py
    PyCalendar/trunk/src/pycalendar/timezonedb.py

Modified: PyCalendar/trunk/src/pycalendar/datetime.py
===================================================================
--- PyCalendar/trunk/src/pycalendar/datetime.py	2014-04-03 00:19:52 UTC (rev 13134)
+++ PyCalendar/trunk/src/pycalendar/datetime.py	2014-04-03 00:42:33 UTC (rev 13135)
@@ -707,10 +707,11 @@
         # Only if different
         s1 = tzid.getTimezoneID()
         if (tzid.getUTC() != self.mTZUTC) or (s1 != self.mTZID):
-            offset_from = self.timeZoneSecondsOffset()
+            if not self.mTZUTC:
+                self.adjustToUTC()
             self.setTimezone(tzid)
-            offset_to = self.timeZoneSecondsOffset()
-            self.offsetSeconds(offset_to - offset_from)
+            offset_to = self.timeZoneSecondsOffset(relative_to_utc=True)
+            self.offsetSeconds(offset_to)
         return self
 
 
@@ -1173,12 +1174,12 @@
         self.changed()
 
 
-    def timeZoneSecondsOffset(self):
+    def timeZoneSecondsOffset(self, relative_to_utc=False):
         if self.mTZUTC:
             return 0
         if self.mTZOffset is None:
             tz = Timezone(utc=self.mTZUTC, tzid=self.mTZID)
-            self.mTZOffset = tz.timeZoneSecondsOffset(self)
+            self.mTZOffset = tz.timeZoneSecondsOffset(self, relative_to_utc)
         return self.mTZOffset
 
 

Modified: PyCalendar/trunk/src/pycalendar/icalendar/calendar.py
===================================================================
--- PyCalendar/trunk/src/pycalendar/icalendar/calendar.py	2014-04-03 00:19:52 UTC (rev 13134)
+++ PyCalendar/trunk/src/pycalendar/icalendar/calendar.py	2014-04-03 00:42:33 UTC (rev 13135)
@@ -545,10 +545,10 @@
         FreeBusy.resolveOverlaps(fb)
 
 
-    def getTimezoneOffsetSeconds(self, tzid, dt):
+    def getTimezoneOffsetSeconds(self, tzid, dt, relative_to_utc=False):
         # Find timezone that matches the name (which is the same as the map key)
         timezone = self.getTimezone(tzid)
-        return timezone.getTimezoneOffsetSeconds(dt) if timezone else 0
+        return timezone.getTimezoneOffsetSeconds(dt, relative_to_utc) if timezone else 0
 
 
     def getTimezoneDescriptor(self, tzid, dt):

Modified: PyCalendar/trunk/src/pycalendar/icalendar/tests/test_timezone.py
===================================================================
--- PyCalendar/trunk/src/pycalendar/icalendar/tests/test_timezone.py	2014-04-03 00:19:52 UTC (rev 13134)
+++ PyCalendar/trunk/src/pycalendar/icalendar/tests/test_timezone.py	2014-04-03 00:42:33 UTC (rev 13135)
@@ -16,6 +16,7 @@
 
 from pycalendar.datetime import DateTime
 from pycalendar.icalendar.calendar import Calendar
+from pycalendar.timezone import Timezone
 import unittest
 
 class TestCalendar(unittest.TestCase):
@@ -24,9 +25,9 @@
 
         data = (
                     ("""BEGIN:VCALENDAR
+VERSION:2.0
 CALSCALE:GREGORIAN
 PRODID:-//calendarserver.org//Zonal//EN
-VERSION:2.0
 BEGIN:VTIMEZONE
 TZID:America/New_York
 X-LIC-LOCATION:America/New_York
@@ -173,18 +174,34 @@
 END:VCALENDAR
 """,
                 (
-                    (DateTime(1942, 2, 8), -5),
-                    (DateTime(1942, 2, 10), -4),
-                    (DateTime(2011, 1, 1), -5),
-                    (DateTime(2011, 4, 1), -4),
-                    (DateTime(2011, 10, 24), -4),
-                    (DateTime(2011, 11, 8), -5),
-                    (DateTime(2006, 1, 1), -5),
-                    (DateTime(2006, 4, 1), -5),
-                    (DateTime(2006, 5, 1), -4),
-                    (DateTime(2006, 10, 1), -4),
-                    (DateTime(2006, 10, 24), -4),
-                    (DateTime(2006, 11, 8), -5),
+                    (DateTime(1942, 2, 8), False, -5),
+                    (DateTime(1942, 2, 10), False, -4),
+                    (DateTime(2011, 1, 1), False, -5),
+                    (DateTime(2011, 4, 1), False, -4),
+                    (DateTime(2011, 10, 24), False, -4),
+                    (DateTime(2011, 11, 8), False, -5),
+                    (DateTime(2006, 1, 1), False, -5),
+                    (DateTime(2006, 4, 1), False, -5),
+                    (DateTime(2006, 5, 1), False, -4),
+                    (DateTime(2006, 10, 1), False, -4),
+                    (DateTime(2006, 10, 24), False, -4),
+                    (DateTime(2006, 11, 8), False, -5),
+                    (DateTime(2014, 3, 8, 23, 0, 0), False, -5),
+                    (DateTime(2014, 3, 9, 0, 0, 0), False, -5),
+                    (DateTime(2014, 3, 9, 3, 0, 0), False, -4),
+                    (DateTime(2014, 3, 9, 8, 0, 0), False, -4),
+                    (DateTime(2014, 3, 8, 23, 0, 0), True, -5),
+                    (DateTime(2014, 3, 9, 0, 0, 0), True, -5),
+                    (DateTime(2014, 3, 9, 3, 0, 0), True, -5),
+                    (DateTime(2014, 3, 9, 8, 0, 0), True, -4),
+                    (DateTime(2014, 11, 1, 23, 0, 0), False, -4),
+                    (DateTime(2014, 11, 2, 0, 0, 0), False, -4),
+                    (DateTime(2014, 11, 2, 3, 0, 0), False, -5),
+                    (DateTime(2014, 11, 2, 8, 0, 0), False, -5),
+                    (DateTime(2014, 11, 1, 23, 0, 0), True, -4),
+                    (DateTime(2014, 11, 2, 0, 0, 0), True, -4),
+                    (DateTime(2014, 11, 2, 3, 0, 0), True, -4),
+                    (DateTime(2014, 11, 2, 8, 0, 0), True, -5),
                 )
             ),
                     ("""BEGIN:VCALENDAR
@@ -205,10 +222,10 @@
 END:VCALENDAR
 """,
                 (
-                    (DateTime(1942, 2, 8), -8),
-                    (DateTime(1942, 2, 10), -8),
-                    (DateTime(2011, 1, 1), -8),
-                    (DateTime(2011, 4, 1), -8),
+                    (DateTime(1942, 2, 8), False, -8),
+                    (DateTime(1942, 2, 10), False, -8),
+                    (DateTime(2011, 1, 1), False, -8),
+                    (DateTime(2011, 4, 1), False, -8),
                 )
             ),
         )
@@ -218,18 +235,323 @@
             cal = Calendar.parseText(tzdata.replace("\n", "\r\n"))
             tz = cal.getComponents()[0]
 
-            for dt, offset in offsets:
-                tzoffset = tz.getTimezoneOffsetSeconds(dt)
+            for dt, relative_to_utc, offset in offsets:
+                tzoffset = tz.getTimezoneOffsetSeconds(dt, relative_to_utc)
                 self.assertEqual(tzoffset, offset * 60 * 60, "Failed to match offset for %s at %s with caching" % (tz.getID(), dt,))
-            for dt, offset in reversed(offsets):
-                tzoffset = tz.getTimezoneOffsetSeconds(dt)
+            for dt, relative_to_utc, offset in reversed(offsets):
+                tzoffset = tz.getTimezoneOffsetSeconds(dt, relative_to_utc)
                 self.assertEqual(tzoffset, offset * 60 * 60, "Failed to match offset for %s at %s with caching, reversed" % (tz.getID(), dt,))
 
-            for dt, offset in offsets:
+            for dt, relative_to_utc, offset in offsets:
                 tz.mCachedExpandAllMax = None
-                tzoffset = tz.getTimezoneOffsetSeconds(dt)
+                tzoffset = tz.getTimezoneOffsetSeconds(dt, relative_to_utc)
                 self.assertEqual(tzoffset, offset * 60 * 60, "Failed to match offset for %s at %s without caching" % (tz.getID(), dt,))
-            for dt, offset in reversed(offsets):
+            for dt, relative_to_utc, offset in reversed(offsets):
                 tz.mCachedExpandAllMax = None
-                tzoffset = tz.getTimezoneOffsetSeconds(dt)
+                tzoffset = tz.getTimezoneOffsetSeconds(dt, relative_to_utc)
                 self.assertEqual(tzoffset, offset * 60 * 60, "Failed to match offset for %s at %s without caching, reversed" % (tz.getID(), dt,))
+
+
+    def testConversions(self):
+
+        tzdata = """BEGIN:VCALENDAR
+VERSION:2.0
+CALSCALE:GREGORIAN
+PRODID:-//calendarserver.org//Zonal//EN
+BEGIN:VTIMEZONE
+TZID:America/New_York
+X-LIC-LOCATION:America/New_York
+BEGIN:STANDARD
+DTSTART:18831118T120358
+RDATE:18831118T120358
+TZNAME:EST
+TZOFFSETFROM:-045602
+TZOFFSETTO:-0500
+END:STANDARD
+BEGIN:DAYLIGHT
+DTSTART:19180331T020000
+RRULE:FREQ=YEARLY;UNTIL=19190330T070000Z;BYDAY=-1SU;BYMONTH=3
+TZNAME:EDT
+TZOFFSETFROM:-0500
+TZOFFSETTO:-0400
+END:DAYLIGHT
+BEGIN:STANDARD
+DTSTART:19181027T020000
+RRULE:FREQ=YEARLY;UNTIL=19191026T060000Z;BYDAY=-1SU;BYMONTH=10
+TZNAME:EST
+TZOFFSETFROM:-0400
+TZOFFSETTO:-0500
+END:STANDARD
+BEGIN:STANDARD
+DTSTART:19200101T000000
+RDATE:19200101T000000
+RDATE:19420101T000000
+RDATE:19460101T000000
+RDATE:19670101T000000
+TZNAME:EST
+TZOFFSETFROM:-0500
+TZOFFSETTO:-0500
+END:STANDARD
+BEGIN:DAYLIGHT
+DTSTART:19200328T020000
+RDATE:19200328T020000
+RDATE:19740106T020000
+RDATE:19750223T020000
+TZNAME:EDT
+TZOFFSETFROM:-0500
+TZOFFSETTO:-0400
+END:DAYLIGHT
+BEGIN:STANDARD
+DTSTART:19201031T020000
+RDATE:19201031T020000
+RDATE:19450930T020000
+TZNAME:EST
+TZOFFSETFROM:-0400
+TZOFFSETTO:-0500
+END:STANDARD
+BEGIN:DAYLIGHT
+DTSTART:19210424T020000
+RRULE:FREQ=YEARLY;UNTIL=19410427T070000Z;BYDAY=-1SU;BYMONTH=4
+TZNAME:EDT
+TZOFFSETFROM:-0500
+TZOFFSETTO:-0400
+END:DAYLIGHT
+BEGIN:STANDARD
+DTSTART:19210925T020000
+RRULE:FREQ=YEARLY;UNTIL=19410928T060000Z;BYDAY=-1SU;BYMONTH=9
+TZNAME:EST
+TZOFFSETFROM:-0400
+TZOFFSETTO:-0500
+END:STANDARD
+BEGIN:DAYLIGHT
+DTSTART:19420209T020000
+RDATE:19420209T020000
+TZNAME:EWT
+TZOFFSETFROM:-0500
+TZOFFSETTO:-0400
+END:DAYLIGHT
+BEGIN:DAYLIGHT
+DTSTART:19450814T190000
+RDATE:19450814T190000
+TZNAME:EPT
+TZOFFSETFROM:-0400
+TZOFFSETTO:-0400
+END:DAYLIGHT
+BEGIN:DAYLIGHT
+DTSTART:19460428T020000
+RRULE:FREQ=YEARLY;UNTIL=19660424T070000Z;BYDAY=-1SU;BYMONTH=4
+TZNAME:EDT
+TZOFFSETFROM:-0500
+TZOFFSETTO:-0400
+END:DAYLIGHT
+BEGIN:STANDARD
+DTSTART:19460929T020000
+RRULE:FREQ=YEARLY;UNTIL=19540926T060000Z;BYDAY=-1SU;BYMONTH=9
+TZNAME:EST
+TZOFFSETFROM:-0400
+TZOFFSETTO:-0500
+END:STANDARD
+BEGIN:STANDARD
+DTSTART:19551030T020000
+RRULE:FREQ=YEARLY;UNTIL=19661030T060000Z;BYDAY=-1SU;BYMONTH=10
+TZNAME:EST
+TZOFFSETFROM:-0400
+TZOFFSETTO:-0500
+END:STANDARD
+BEGIN:DAYLIGHT
+DTSTART:19670430T020000
+RRULE:FREQ=YEARLY;UNTIL=19730429T070000Z;BYDAY=-1SU;BYMONTH=4
+TZNAME:EDT
+TZOFFSETFROM:-0500
+TZOFFSETTO:-0400
+END:DAYLIGHT
+BEGIN:STANDARD
+DTSTART:19671029T020000
+RRULE:FREQ=YEARLY;UNTIL=20061029T060000Z;BYDAY=-1SU;BYMONTH=10
+TZNAME:EST
+TZOFFSETFROM:-0400
+TZOFFSETTO:-0500
+END:STANDARD
+BEGIN:DAYLIGHT
+DTSTART:19760425T020000
+RRULE:FREQ=YEARLY;UNTIL=19860427T070000Z;BYDAY=-1SU;BYMONTH=4
+TZNAME:EDT
+TZOFFSETFROM:-0500
+TZOFFSETTO:-0400
+END:DAYLIGHT
+BEGIN:DAYLIGHT
+DTSTART:19870405T020000
+RRULE:FREQ=YEARLY;UNTIL=20060402T070000Z;BYDAY=1SU;BYMONTH=4
+TZNAME:EDT
+TZOFFSETFROM:-0500
+TZOFFSETTO:-0400
+END:DAYLIGHT
+BEGIN:DAYLIGHT
+DTSTART:20070311T020000
+RRULE:FREQ=YEARLY;BYDAY=2SU;BYMONTH=3
+TZNAME:EDT
+TZOFFSETFROM:-0500
+TZOFFSETTO:-0400
+END:DAYLIGHT
+BEGIN:STANDARD
+DTSTART:20071104T020000
+RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=11
+TZNAME:EST
+TZOFFSETFROM:-0400
+TZOFFSETTO:-0500
+END:STANDARD
+END:VTIMEZONE
+BEGIN:VTIMEZONE
+TZID:America/Los_Angeles
+X-LIC-LOCATION:America/Los_Angeles
+BEGIN:STANDARD
+DTSTART:18831118T120702
+RDATE:18831118T120702
+TZNAME:PST
+TZOFFSETFROM:-075258
+TZOFFSETTO:-0800
+END:STANDARD
+BEGIN:DAYLIGHT
+DTSTART:19180331T020000
+RRULE:FREQ=YEARLY;UNTIL=19190330T100000Z;BYDAY=-1SU;BYMONTH=3
+TZNAME:PDT
+TZOFFSETFROM:-0800
+TZOFFSETTO:-0700
+END:DAYLIGHT
+BEGIN:STANDARD
+DTSTART:19181027T020000
+RRULE:FREQ=YEARLY;UNTIL=19191026T090000Z;BYDAY=-1SU;BYMONTH=10
+TZNAME:PST
+TZOFFSETFROM:-0700
+TZOFFSETTO:-0800
+END:STANDARD
+BEGIN:DAYLIGHT
+DTSTART:19420209T020000
+RDATE:19420209T020000
+TZNAME:PWT
+TZOFFSETFROM:-0800
+TZOFFSETTO:-0700
+END:DAYLIGHT
+BEGIN:DAYLIGHT
+DTSTART:19450814T160000
+RDATE:19450814T160000
+TZNAME:PPT
+TZOFFSETFROM:-0700
+TZOFFSETTO:-0700
+END:DAYLIGHT
+BEGIN:STANDARD
+DTSTART:19450930T020000
+RDATE:19450930T020000
+RDATE:19490101T020000
+TZNAME:PST
+TZOFFSETFROM:-0700
+TZOFFSETTO:-0800
+END:STANDARD
+BEGIN:STANDARD
+DTSTART:19460101T000000
+RDATE:19460101T000000
+RDATE:19670101T000000
+TZNAME:PST
+TZOFFSETFROM:-0800
+TZOFFSETTO:-0800
+END:STANDARD
+BEGIN:DAYLIGHT
+DTSTART:19480314T020000
+RDATE:19480314T020000
+RDATE:19740106T020000
+RDATE:19750223T020000
+TZNAME:PDT
+TZOFFSETFROM:-0800
+TZOFFSETTO:-0700
+END:DAYLIGHT
+BEGIN:DAYLIGHT
+DTSTART:19500430T020000
+RRULE:FREQ=YEARLY;UNTIL=19660424T100000Z;BYDAY=-1SU;BYMONTH=4
+TZNAME:PDT
+TZOFFSETFROM:-0800
+TZOFFSETTO:-0700
+END:DAYLIGHT
+BEGIN:STANDARD
+DTSTART:19500924T020000
+RRULE:FREQ=YEARLY;UNTIL=19610924T090000Z;BYDAY=-1SU;BYMONTH=9
+TZNAME:PST
+TZOFFSETFROM:-0700
+TZOFFSETTO:-0800
+END:STANDARD
+BEGIN:STANDARD
+DTSTART:19621028T020000
+RRULE:FREQ=YEARLY;UNTIL=19661030T090000Z;BYDAY=-1SU;BYMONTH=10
+TZNAME:PST
+TZOFFSETFROM:-0700
+TZOFFSETTO:-0800
+END:STANDARD
+BEGIN:DAYLIGHT
+DTSTART:19670430T020000
+RRULE:FREQ=YEARLY;UNTIL=19730429T100000Z;BYDAY=-1SU;BYMONTH=4
+TZNAME:PDT
+TZOFFSETFROM:-0800
+TZOFFSETTO:-0700
+END:DAYLIGHT
+BEGIN:STANDARD
+DTSTART:19671029T020000
+RRULE:FREQ=YEARLY;UNTIL=20061029T090000Z;BYDAY=-1SU;BYMONTH=10
+TZNAME:PST
+TZOFFSETFROM:-0700
+TZOFFSETTO:-0800
+END:STANDARD
+BEGIN:DAYLIGHT
+DTSTART:19760425T020000
+RRULE:FREQ=YEARLY;UNTIL=19860427T100000Z;BYDAY=-1SU;BYMONTH=4
+TZNAME:PDT
+TZOFFSETFROM:-0800
+TZOFFSETTO:-0700
+END:DAYLIGHT
+BEGIN:DAYLIGHT
+DTSTART:19870405T020000
+RRULE:FREQ=YEARLY;UNTIL=20060402T100000Z;BYDAY=1SU;BYMONTH=4
+TZNAME:PDT
+TZOFFSETFROM:-0800
+TZOFFSETTO:-0700
+END:DAYLIGHT
+BEGIN:DAYLIGHT
+DTSTART:20070311T020000
+RRULE:FREQ=YEARLY;BYDAY=2SU;BYMONTH=3
+TZNAME:PDT
+TZOFFSETFROM:-0800
+TZOFFSETTO:-0700
+END:DAYLIGHT
+BEGIN:STANDARD
+DTSTART:20071104T020000
+RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=11
+TZNAME:PST
+TZOFFSETFROM:-0700
+TZOFFSETTO:-0800
+END:STANDARD
+END:VTIMEZONE
+END:VCALENDAR
+"""
+        data = (
+            (
+                DateTime(2014, 3, 8, 23, 0, 0, Timezone(tzid="America/New_York")),
+                DateTime(2014, 3, 8, 20, 0, 0, Timezone(tzid="America/Los_Angeles")),
+            ),
+            (
+                DateTime(2014, 3, 9, 3, 0, 0, Timezone(utc=True)),
+                DateTime(2014, 3, 8, 19, 0, 0, Timezone(tzid="America/Los_Angeles")),
+            ),
+            (
+                DateTime(2014, 3, 9, 13, 0, 0, Timezone(utc=True)),
+                DateTime(2014, 3, 9, 6, 0, 0, Timezone(tzid="America/Los_Angeles")),
+            ),
+        )
+
+        Calendar.parseText(tzdata.replace("\n", "\r\n"))
+
+        for dtfrom, dtto in data:
+
+            self.assertEqual(dtfrom, dtto)
+
+            newdtfrom = dtfrom.duplicate()
+            newdtfrom.adjustTimezone(dtto.getTimezone())
+            self.assertEqual(newdtfrom, dtto)
+            self.assertEqual(newdtfrom.getHours(), dtto.getHours())

Modified: PyCalendar/trunk/src/pycalendar/icalendar/vtimezone.py
===================================================================
--- PyCalendar/trunk/src/pycalendar/icalendar/vtimezone.py	2014-04-03 00:19:52 UTC (rev 13134)
+++ PyCalendar/trunk/src/pycalendar/icalendar/vtimezone.py	2014-04-03 00:42:33 UTC (rev 13135)
@@ -135,10 +135,21 @@
         return self.mUTCOffsetSortKey
 
 
-    def getTimezoneOffsetSeconds(self, dt):
+    def getTimezoneOffsetSeconds(self, dt, relative_to_utc=False):
         """
         Caching implementation of expansion. We cache the entire set of transitions up to one year ahead
         of the requested time.
+
+        We need to handle calculating the offset based on both a local time and a UTC time. The later
+        is needed when converting from one timezone offset to another which is best done by determining
+        the UTC time as an intermediate value.
+
+        @param dt: a date-time to determine the offset for
+        @type dt: L{DateTime}
+        @param relative_to_utc: if L{False}, then the L{dt} value is the local time for which an
+            offset is desired, if L{True}, then the L{dt} value is a UTC time for which an
+            offset is desired.
+        @type relative_to_utc: L{bool}
         """
 
         # Need to make the incoming date-time relative to the DTSTART in the
@@ -161,15 +172,15 @@
 
         # Now search for the transition just below the time we want
         if len(self.mCachedExpandAll):
-            cacheKey = (temp.mYear, temp.mMonth, temp.mDay, temp.mHours, temp.mMinutes,)
+            cacheKey = (temp.mYear, temp.mMonth, temp.mDay, temp.mHours, temp.mMinutes, relative_to_utc)
             i = self.mCachedOffsets.get(cacheKey)
             if i is None:
-                i = VTimezone.tuple_bisect_right(self.mCachedExpandAll, temp)
+                i = VTimezone.tuple_bisect_right(self.mCachedExpandAll, temp, relative_to_utc)
                 if len(self.mCachedOffsets) >= self.UTCOFFSET_CACHE_MAX_ENTRIES:
                     self.mCachedOffsets = {}
                 self.mCachedOffsets[cacheKey] = i
             if i != 0:
-                return self.mCachedExpandAll[i - 1][2]
+                return self.mCachedExpandAll[i - 1][3]
 
         return 0
 
@@ -210,7 +221,7 @@
 
 
     @staticmethod
-    def tuple_bisect_right(a, x):
+    def tuple_bisect_right(a, x, relative_to_utc=False):
         """
         Same as bisect_right except that the values being compared are the first elements
         of a tuple.
@@ -220,7 +231,7 @@
         hi = len(a)
         while lo < hi:
             mid = (lo + hi) // 2
-            if x < a[mid][0]:
+            if x < a[mid][1 if relative_to_utc else 0]:
                 hi = mid
             else:
                 lo = mid + 1
@@ -262,11 +273,18 @@
         results = []
         for item in self.mComponents:
             results.extend(item.expandAll(start, end, with_name))
-        results = [x for x in set(results)]
-        results.sort(key=lambda x: x[0].getPosixTime())
-        return results
 
+        utc_results = []
+        for items in set(results):
+            items = list(items)
+            utcdt = items[0].duplicate()
+            utcdt.offsetSeconds(-items[1])
+            items.insert(1, utcdt)
+            utc_results.append(tuple(items))
+        utc_results.sort(key=lambda x: x[0].getPosixTime())
+        return utc_results
 
+
     def sortedPropertyKeyOrder(self):
         return (
             definitions.cICalProperty_TZID,

Modified: PyCalendar/trunk/src/pycalendar/timezone.py
===================================================================
--- PyCalendar/trunk/src/pycalendar/timezone.py	2014-04-03 00:19:52 UTC (rev 13134)
+++ PyCalendar/trunk/src/pycalendar/timezone.py	2014-04-03 00:42:33 UTC (rev 13135)
@@ -100,16 +100,16 @@
         return not self.mUTC and self.mTimezone is not None
 
 
-    def timeZoneSecondsOffset(self, dt):
+    def timeZoneSecondsOffset(self, dt, relative_to_utc=False):
         if self.mUTC:
             return 0
         elif self.mTimezone is None:
-            return TimezoneDatabase.getTimezoneOffsetSeconds(Timezone.sDefaultTimezone.getTimezoneID(), dt)
+            return TimezoneDatabase.getTimezoneOffsetSeconds(Timezone.sDefaultTimezone.getTimezoneID(), dt, relative_to_utc)
         elif isinstance(self.mTimezone, int):
             return self.mTimezone
         else:
             # Look up timezone and resolve date using default timezones
-            return TimezoneDatabase.getTimezoneOffsetSeconds(self.mTimezone, dt)
+            return TimezoneDatabase.getTimezoneOffsetSeconds(self.mTimezone, dt, relative_to_utc)
 
 
     def timeZoneDescriptor(self, dt):

Modified: PyCalendar/trunk/src/pycalendar/timezonedb.py
===================================================================
--- PyCalendar/trunk/src/pycalendar/timezonedb.py	2014-04-03 00:19:52 UTC (rev 13134)
+++ PyCalendar/trunk/src/pycalendar/timezonedb.py	2014-04-03 00:42:33 UTC (rev 13135)
@@ -94,11 +94,11 @@
 
 
     @staticmethod
-    def getTimezoneOffsetSeconds(tzid, dt):
+    def getTimezoneOffsetSeconds(tzid, dt, relative_to_utc=False):
         # Cache it first
         tz = TimezoneDatabase.getTimezone(tzid)
         if tz is not None:
-            return tz.getTimezoneOffsetSeconds(dt)
+            return tz.getTimezoneOffsetSeconds(dt, relative_to_utc)
         else:
             return 0
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140402/8bbadc63/attachment-0001.html>


More information about the calendarserver-changes mailing list