[Zope-Checkins] SVN: Zope/branches/slinkp-datetime-200007/lib/python/DateTime/ Fix for launchpad #200007: DateTime() surprisingly changes timezone if passed a DateTime instance.

Paul Winkler pw_lists at slinkp.com
Fri Apr 25 16:58:05 EDT 2008


Log message for revision 85734:
  Fix for launchpad #200007: DateTime() surprisingly changes timezone if passed a DateTime instance.

Changed:
  U   Zope/branches/slinkp-datetime-200007/lib/python/DateTime/DateTime.py
  U   Zope/branches/slinkp-datetime-200007/lib/python/DateTime/tests/testDateTime.py

-=-
Modified: Zope/branches/slinkp-datetime-200007/lib/python/DateTime/DateTime.py
===================================================================
--- Zope/branches/slinkp-datetime-200007/lib/python/DateTime/DateTime.py	2008-04-25 20:22:51 UTC (rev 85733)
+++ Zope/branches/slinkp-datetime-200007/lib/python/DateTime/DateTime.py	2008-04-25 20:58:04 UTC (rev 85734)
@@ -68,7 +68,7 @@
   (?:-?                             # one optional dash
    (?:                              # followed by:
     (?P<year_day>\d\d\d             #  three digits year day
-     (?!\d))                        #  when there's no fourth digit
+     (?!\d))                        #  when there is no fourth digit
    |                                # or:
     W                               #  one W
     (?P<week>\d\d)                  #  two digits week
@@ -586,12 +586,11 @@
                 DateTime instance.
                 """
                 t = arg.timeTime()
-                lt = safelocaltime(t)
-                tz = self.localZone(lt)
+                tz = arg.timezone()
                 ms = (t - math.floor(t))
                 s,d = _calcSD(t)
-                yr,mo,dy,hr,mn,sc=lt[:6]
-                sc=sc+ms
+                yr,mo,dy,hr,mn,sc = gmtime(t)[:6]
+                sc = sc + ms
             
             elif isinstance(arg, datetime):
                 yr,mo,dy,hr,mn,sc,numerictz,tznaive=self._parse_iso8601_preserving_tznaive(arg.isoformat())

Modified: Zope/branches/slinkp-datetime-200007/lib/python/DateTime/tests/testDateTime.py
===================================================================
--- Zope/branches/slinkp-datetime-200007/lib/python/DateTime/tests/testDateTime.py	2008-04-25 20:22:51 UTC (rev 85733)
+++ Zope/branches/slinkp-datetime-200007/lib/python/DateTime/tests/testDateTime.py	2008-04-25 20:58:04 UTC (rev 85734)
@@ -386,6 +386,19 @@
         d = DateTime('1999/04/12')
         self.assertEqual(DateTime(d), d)
 
+    def testCopyConstructorPreservesTimezone(self):
+        # test for https://bugs.launchpad.net/zope2/+bug/200007
+        # This always worked in the local timezone, so we need at least
+        # two tests with different zones to be sure at least one of them
+        # is not local.
+        d = DateTime('2004/04/04')
+        self.assertEqual(DateTime(d).timezone(), d.timezone())
+        d2 = DateTime('2008/04/25 12:00:00 EST')
+        self.assertEqual(DateTime(d2).timezone(), d2.timezone())
+        d3 = DateTime('2008/04/25 12:00:00 PST')
+        self.assertEqual(DateTime(d3).timezone(), d3.timezone())
+
+
     def testRFC822(self):
         # rfc822 conversion
         dt = DateTime('2002-05-02T08:00:00+00:00')



More information about the Zope-Checkins mailing list