Commit 5f8c042f authored by Paul Winkler's avatar Paul Winkler

Merged the slinkp-datetime-200007 branch: fix the DateTime(anotherDateTime)...

Merged the slinkp-datetime-200007 branch: fix the DateTime(anotherDateTime) constructor to preserve timezones.
parent 7a5a1dcd
...@@ -8,6 +8,9 @@ Zope Changes ...@@ -8,6 +8,9 @@ Zope Changes
Bugs fixed Bugs fixed
- Launchpad #200007: DateTime(anotherDateTime) now preserves the
timezone.
- Launchpad #213311: Handle "unsubscriptable object" errors - Launchpad #213311: Handle "unsubscriptable object" errors
during publishing traversal. during publishing traversal.
......
...@@ -704,12 +704,11 @@ class DateTime: ...@@ -704,12 +704,11 @@ class DateTime:
if isinstance(arg, DateTime): if isinstance(arg, DateTime):
""" Construct a new DateTime instance from a given DateTime instance """ """ Construct a new DateTime instance from a given DateTime instance """
t = arg.timeTime() t = arg.timeTime()
lt = safelocaltime(t) tz = arg.timezone()
tz = self.localZone(lt)
ms = (t - math.floor(t)) ms = (t - math.floor(t))
s,d = _calcSD(t) s,d = _calcSD(t)
yr,mo,dy,hr,mn,sc=lt[:6] yr,mo,dy,hr,mn,sc = gmtime(t)[:6]
sc=sc+ms sc = sc + ms
elif isinstance(arg, (unicode, str)) and arg.lower() in self._tzinfo._zidx: elif isinstance(arg, (unicode, str)) and arg.lower() in self._tzinfo._zidx:
# Current time, to be displayed in specified timezone # Current time, to be displayed in specified timezone
......
...@@ -299,6 +299,19 @@ class DateTimeTests(unittest.TestCase): ...@@ -299,6 +299,19 @@ class DateTimeTests(unittest.TestCase):
d = DateTime('1999/04/12') d = DateTime('1999/04/12')
self.assertEqual(DateTime(d), d) 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): def testRFC822(self):
'''rfc822 conversion''' '''rfc822 conversion'''
dt = DateTime('2002-05-02T08:00:00+00:00') dt = DateTime('2002-05-02T08:00:00+00:00')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment