DateTime() changes timezone if passed a DateTime instance

Bug #200007 reported by Paul Winkler
4
Affects Status Importance Assigned to Milestone
Zope 2
Fix Released
Undecided
Paul Winkler

Bug Description

(note, this feature was added in response to #143073 )
It appears that if the argument to DateTime is a DateTime instance, its timezone gets set to the local timezone, regardless of the passed value.

I think this is wrong behavior. The docstring says "If the DateTime function is invoked with a single argument that is a DateTime instance, a copy of the passed object will be created." It doesn't say anything about the copy possibly having a different timezone...

To demonstrate, you need to experiment with timezones *other than your local zone*.
For example, I'm in US/Eastern, so I can demonstrate with US/Pacific.

>>> from DateTime import DateTime
>>> dt1 = DateTime('2001/01/01 12:00 PM PST')
>>> dt1.timezone()
'US/Pacific'
>>> DateTime(dt1) == dt1
True
>>> DateTime(dt1).timezone()
'US/Eastern'

Notice that the second datetime is in a different zone!
You can also see this in the various string representations:

>>> dt1.ISO8601()
'2001-01-01T12:00:00-08:00'
>>> DateTime(dt1).ISO8601()
'2001-01-01T15:00:00-05:00'

Revision history for this message
Paul Winkler (slinkp) wrote :

Fixed on branch svn://svn.zope.org/repos/main/Zope/branches/slinkp-datetime-200007
I'll bring this up on zope-dev; if nobody objects in the next few days, I'll commit to trunk, 2.11, 2.10, and 2.9.

Changed in zope2:
assignee: nobody → slinkp
status: New → In Progress
Revision history for this message
Paul Winkler (slinkp) wrote :

Released in Zope 2.9.9 and 2.10.6

Changed in zope2:
status: In Progress → Fix Released
Revision history for this message
Artur Zaprzała (arturz) wrote :

The patch at http://svn.zope.org/Zope/branches/2.11/lib/python/DateTime/DateTime.py?rev=85834&r1=82440&r2=85834 for this bug is broken. Try this in ZOPE 2.11.1:
>>> dt = DateTime()
>>> DateTime(dt)==dt
True # OK
>>> str(DateTime(dt))==str(dt)
False # Should be True

Values of self._t and self._tz are preserved, but self._hour is not.

Revision history for this message
Paul Winkler (slinkp) wrote :

Good catch, thanks! Since the timezone fix is already released in zope 2.10 and 2.11, I have opened this as a new bug, #267545

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.