<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[13135] PyCalendar/trunk/src/pycalendar</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.calendarserver.org//changeset/13135">13135</a></dd>
<dt>Author</dt> <dd>cdaboo@apple.com</dd>
<dt>Date</dt> <dd>2014-04-02 17:42:33 -0700 (Wed, 02 Apr 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Make sure converting from one timezone to another works correctly near a DST change.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#PyCalendartrunksrcpycalendardatetimepy">PyCalendar/trunk/src/pycalendar/datetime.py</a></li>
<li><a href="#PyCalendartrunksrcpycalendaricalendarcalendarpy">PyCalendar/trunk/src/pycalendar/icalendar/calendar.py</a></li>
<li><a href="#PyCalendartrunksrcpycalendaricalendarteststest_timezonepy">PyCalendar/trunk/src/pycalendar/icalendar/tests/test_timezone.py</a></li>
<li><a href="#PyCalendartrunksrcpycalendaricalendarvtimezonepy">PyCalendar/trunk/src/pycalendar/icalendar/vtimezone.py</a></li>
<li><a href="#PyCalendartrunksrcpycalendartimezonepy">PyCalendar/trunk/src/pycalendar/timezone.py</a></li>
<li><a href="#PyCalendartrunksrcpycalendartimezonedbpy">PyCalendar/trunk/src/pycalendar/timezonedb.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="PyCalendartrunksrcpycalendardatetimepy"></a>
<div class="modfile"><h4>Modified: PyCalendar/trunk/src/pycalendar/datetime.py (13134 => 13135)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -707,10 +707,11 @@
</span><span class="cx">         # Only if different
</span><span class="cx">         s1 = tzid.getTimezoneID()
</span><span class="cx">         if (tzid.getUTC() != self.mTZUTC) or (s1 != self.mTZID):
</span><del>-            offset_from = self.timeZoneSecondsOffset()
</del><ins>+            if not self.mTZUTC:
+                self.adjustToUTC()
</ins><span class="cx">             self.setTimezone(tzid)
</span><del>-            offset_to = self.timeZoneSecondsOffset()
-            self.offsetSeconds(offset_to - offset_from)
</del><ins>+            offset_to = self.timeZoneSecondsOffset(relative_to_utc=True)
+            self.offsetSeconds(offset_to)
</ins><span class="cx">         return self
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -1173,12 +1174,12 @@
</span><span class="cx">         self.changed()
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def timeZoneSecondsOffset(self):
</del><ins>+    def timeZoneSecondsOffset(self, relative_to_utc=False):
</ins><span class="cx">         if self.mTZUTC:
</span><span class="cx">             return 0
</span><span class="cx">         if self.mTZOffset is None:
</span><span class="cx">             tz = Timezone(utc=self.mTZUTC, tzid=self.mTZID)
</span><del>-            self.mTZOffset = tz.timeZoneSecondsOffset(self)
</del><ins>+            self.mTZOffset = tz.timeZoneSecondsOffset(self, relative_to_utc)
</ins><span class="cx">         return self.mTZOffset
</span><span class="cx"> 
</span><span class="cx"> 
</span></span></pre></div>
<a id="PyCalendartrunksrcpycalendaricalendarcalendarpy"></a>
<div class="modfile"><h4>Modified: PyCalendar/trunk/src/pycalendar/icalendar/calendar.py (13134 => 13135)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -545,10 +545,10 @@
</span><span class="cx">         FreeBusy.resolveOverlaps(fb)
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def getTimezoneOffsetSeconds(self, tzid, dt):
</del><ins>+    def getTimezoneOffsetSeconds(self, tzid, dt, relative_to_utc=False):
</ins><span class="cx">         # Find timezone that matches the name (which is the same as the map key)
</span><span class="cx">         timezone = self.getTimezone(tzid)
</span><del>-        return timezone.getTimezoneOffsetSeconds(dt) if timezone else 0
</del><ins>+        return timezone.getTimezoneOffsetSeconds(dt, relative_to_utc) if timezone else 0
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def getTimezoneDescriptor(self, tzid, dt):
</span></span></pre></div>
<a id="PyCalendartrunksrcpycalendaricalendarteststest_timezonepy"></a>
<div class="modfile"><h4>Modified: PyCalendar/trunk/src/pycalendar/icalendar/tests/test_timezone.py (13134 => 13135)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -16,6 +16,7 @@
</span><span class="cx"> 
</span><span class="cx"> from pycalendar.datetime import DateTime
</span><span class="cx"> from pycalendar.icalendar.calendar import Calendar
</span><ins>+from pycalendar.timezone import Timezone
</ins><span class="cx"> import unittest
</span><span class="cx"> 
</span><span class="cx"> class TestCalendar(unittest.TestCase):
</span><span class="lines">@@ -24,9 +25,9 @@
</span><span class="cx"> 
</span><span class="cx">         data = (
</span><span class="cx">                     (&quot;&quot;&quot;BEGIN:VCALENDAR
</span><ins>+VERSION:2.0
</ins><span class="cx"> CALSCALE:GREGORIAN
</span><span class="cx"> PRODID:-//calendarserver.org//Zonal//EN
</span><del>-VERSION:2.0
</del><span class="cx"> BEGIN:VTIMEZONE
</span><span class="cx"> TZID:America/New_York
</span><span class="cx"> X-LIC-LOCATION:America/New_York
</span><span class="lines">@@ -173,18 +174,34 @@
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><span class="cx">                 (
</span><del>-                    (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),
</del><ins>+                    (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),
</ins><span class="cx">                 )
</span><span class="cx">             ),
</span><span class="cx">                     (&quot;&quot;&quot;BEGIN:VCALENDAR
</span><span class="lines">@@ -205,10 +222,10 @@
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><span class="cx">                 (
</span><del>-                    (DateTime(1942, 2, 8), -8),
-                    (DateTime(1942, 2, 10), -8),
-                    (DateTime(2011, 1, 1), -8),
-                    (DateTime(2011, 4, 1), -8),
</del><ins>+                    (DateTime(1942, 2, 8), False, -8),
+                    (DateTime(1942, 2, 10), False, -8),
+                    (DateTime(2011, 1, 1), False, -8),
+                    (DateTime(2011, 4, 1), False, -8),
</ins><span class="cx">                 )
</span><span class="cx">             ),
</span><span class="cx">         )
</span><span class="lines">@@ -218,18 +235,323 @@
</span><span class="cx">             cal = Calendar.parseText(tzdata.replace(&quot;\n&quot;, &quot;\r\n&quot;))
</span><span class="cx">             tz = cal.getComponents()[0]
</span><span class="cx"> 
</span><del>-            for dt, offset in offsets:
-                tzoffset = tz.getTimezoneOffsetSeconds(dt)
</del><ins>+            for dt, relative_to_utc, offset in offsets:
+                tzoffset = tz.getTimezoneOffsetSeconds(dt, relative_to_utc)
</ins><span class="cx">                 self.assertEqual(tzoffset, offset * 60 * 60, &quot;Failed to match offset for %s at %s with caching&quot; % (tz.getID(), dt,))
</span><del>-            for dt, offset in reversed(offsets):
-                tzoffset = tz.getTimezoneOffsetSeconds(dt)
</del><ins>+            for dt, relative_to_utc, offset in reversed(offsets):
+                tzoffset = tz.getTimezoneOffsetSeconds(dt, relative_to_utc)
</ins><span class="cx">                 self.assertEqual(tzoffset, offset * 60 * 60, &quot;Failed to match offset for %s at %s with caching, reversed&quot; % (tz.getID(), dt,))
</span><span class="cx"> 
</span><del>-            for dt, offset in offsets:
</del><ins>+            for dt, relative_to_utc, offset in offsets:
</ins><span class="cx">                 tz.mCachedExpandAllMax = None
</span><del>-                tzoffset = tz.getTimezoneOffsetSeconds(dt)
</del><ins>+                tzoffset = tz.getTimezoneOffsetSeconds(dt, relative_to_utc)
</ins><span class="cx">                 self.assertEqual(tzoffset, offset * 60 * 60, &quot;Failed to match offset for %s at %s without caching&quot; % (tz.getID(), dt,))
</span><del>-            for dt, offset in reversed(offsets):
</del><ins>+            for dt, relative_to_utc, offset in reversed(offsets):
</ins><span class="cx">                 tz.mCachedExpandAllMax = None
</span><del>-                tzoffset = tz.getTimezoneOffsetSeconds(dt)
</del><ins>+                tzoffset = tz.getTimezoneOffsetSeconds(dt, relative_to_utc)
</ins><span class="cx">                 self.assertEqual(tzoffset, offset * 60 * 60, &quot;Failed to match offset for %s at %s without caching, reversed&quot; % (tz.getID(), dt,))
</span><ins>+
+
+    def testConversions(self):
+
+        tzdata = &quot;&quot;&quot;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
+&quot;&quot;&quot;
+        data = (
+            (
+                DateTime(2014, 3, 8, 23, 0, 0, Timezone(tzid=&quot;America/New_York&quot;)),
+                DateTime(2014, 3, 8, 20, 0, 0, Timezone(tzid=&quot;America/Los_Angeles&quot;)),
+            ),
+            (
+                DateTime(2014, 3, 9, 3, 0, 0, Timezone(utc=True)),
+                DateTime(2014, 3, 8, 19, 0, 0, Timezone(tzid=&quot;America/Los_Angeles&quot;)),
+            ),
+            (
+                DateTime(2014, 3, 9, 13, 0, 0, Timezone(utc=True)),
+                DateTime(2014, 3, 9, 6, 0, 0, Timezone(tzid=&quot;America/Los_Angeles&quot;)),
+            ),
+        )
+
+        Calendar.parseText(tzdata.replace(&quot;\n&quot;, &quot;\r\n&quot;))
+
+        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())
</ins></span></pre></div>
<a id="PyCalendartrunksrcpycalendaricalendarvtimezonepy"></a>
<div class="modfile"><h4>Modified: PyCalendar/trunk/src/pycalendar/icalendar/vtimezone.py (13134 => 13135)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -135,10 +135,21 @@
</span><span class="cx">         return self.mUTCOffsetSortKey
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def getTimezoneOffsetSeconds(self, dt):
</del><ins>+    def getTimezoneOffsetSeconds(self, dt, relative_to_utc=False):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Caching implementation of expansion. We cache the entire set of transitions up to one year ahead
</span><span class="cx">         of the requested time.
</span><ins>+
+        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}
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">         # Need to make the incoming date-time relative to the DTSTART in the
</span><span class="lines">@@ -161,15 +172,15 @@
</span><span class="cx"> 
</span><span class="cx">         # Now search for the transition just below the time we want
</span><span class="cx">         if len(self.mCachedExpandAll):
</span><del>-            cacheKey = (temp.mYear, temp.mMonth, temp.mDay, temp.mHours, temp.mMinutes,)
</del><ins>+            cacheKey = (temp.mYear, temp.mMonth, temp.mDay, temp.mHours, temp.mMinutes, relative_to_utc)
</ins><span class="cx">             i = self.mCachedOffsets.get(cacheKey)
</span><span class="cx">             if i is None:
</span><del>-                i = VTimezone.tuple_bisect_right(self.mCachedExpandAll, temp)
</del><ins>+                i = VTimezone.tuple_bisect_right(self.mCachedExpandAll, temp, relative_to_utc)
</ins><span class="cx">                 if len(self.mCachedOffsets) &gt;= self.UTCOFFSET_CACHE_MAX_ENTRIES:
</span><span class="cx">                     self.mCachedOffsets = {}
</span><span class="cx">                 self.mCachedOffsets[cacheKey] = i
</span><span class="cx">             if i != 0:
</span><del>-                return self.mCachedExpandAll[i - 1][2]
</del><ins>+                return self.mCachedExpandAll[i - 1][3]
</ins><span class="cx"> 
</span><span class="cx">         return 0
</span><span class="cx"> 
</span><span class="lines">@@ -210,7 +221,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @staticmethod
</span><del>-    def tuple_bisect_right(a, x):
</del><ins>+    def tuple_bisect_right(a, x, relative_to_utc=False):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Same as bisect_right except that the values being compared are the first elements
</span><span class="cx">         of a tuple.
</span><span class="lines">@@ -220,7 +231,7 @@
</span><span class="cx">         hi = len(a)
</span><span class="cx">         while lo &lt; hi:
</span><span class="cx">             mid = (lo + hi) // 2
</span><del>-            if x &lt; a[mid][0]:
</del><ins>+            if x &lt; a[mid][1 if relative_to_utc else 0]:
</ins><span class="cx">                 hi = mid
</span><span class="cx">             else:
</span><span class="cx">                 lo = mid + 1
</span><span class="lines">@@ -262,11 +273,18 @@
</span><span class="cx">         results = []
</span><span class="cx">         for item in self.mComponents:
</span><span class="cx">             results.extend(item.expandAll(start, end, with_name))
</span><del>-        results = [x for x in set(results)]
-        results.sort(key=lambda x: x[0].getPosixTime())
-        return results
</del><span class="cx"> 
</span><ins>+        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
</ins><span class="cx"> 
</span><ins>+
</ins><span class="cx">     def sortedPropertyKeyOrder(self):
</span><span class="cx">         return (
</span><span class="cx">             definitions.cICalProperty_TZID,
</span></span></pre></div>
<a id="PyCalendartrunksrcpycalendartimezonepy"></a>
<div class="modfile"><h4>Modified: PyCalendar/trunk/src/pycalendar/timezone.py (13134 => 13135)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -100,16 +100,16 @@
</span><span class="cx">         return not self.mUTC and self.mTimezone is not None
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def timeZoneSecondsOffset(self, dt):
</del><ins>+    def timeZoneSecondsOffset(self, dt, relative_to_utc=False):
</ins><span class="cx">         if self.mUTC:
</span><span class="cx">             return 0
</span><span class="cx">         elif self.mTimezone is None:
</span><del>-            return TimezoneDatabase.getTimezoneOffsetSeconds(Timezone.sDefaultTimezone.getTimezoneID(), dt)
</del><ins>+            return TimezoneDatabase.getTimezoneOffsetSeconds(Timezone.sDefaultTimezone.getTimezoneID(), dt, relative_to_utc)
</ins><span class="cx">         elif isinstance(self.mTimezone, int):
</span><span class="cx">             return self.mTimezone
</span><span class="cx">         else:
</span><span class="cx">             # Look up timezone and resolve date using default timezones
</span><del>-            return TimezoneDatabase.getTimezoneOffsetSeconds(self.mTimezone, dt)
</del><ins>+            return TimezoneDatabase.getTimezoneOffsetSeconds(self.mTimezone, dt, relative_to_utc)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def timeZoneDescriptor(self, dt):
</span></span></pre></div>
<a id="PyCalendartrunksrcpycalendartimezonedbpy"></a>
<div class="modfile"><h4>Modified: PyCalendar/trunk/src/pycalendar/timezonedb.py (13134 => 13135)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -94,11 +94,11 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @staticmethod
</span><del>-    def getTimezoneOffsetSeconds(tzid, dt):
</del><ins>+    def getTimezoneOffsetSeconds(tzid, dt, relative_to_utc=False):
</ins><span class="cx">         # Cache it first
</span><span class="cx">         tz = TimezoneDatabase.getTimezone(tzid)
</span><span class="cx">         if tz is not None:
</span><del>-            return tz.getTimezoneOffsetSeconds(dt)
</del><ins>+            return tz.getTimezoneOffsetSeconds(dt, relative_to_utc)
</ins><span class="cx">         else:
</span><span class="cx">             return 0
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>