-
Notifications
You must be signed in to change notification settings - Fork 524
Closed
Labels
Milestone
Description
Reproduced in dateutil 2.6.0 and 2.4.2 : Python 2.7.11 |Anaconda custom (x86_64)
from dateutil.tz import gettz
from datetime import datetime as dt
tz = gettz('Europe/London')
x = dt(2007, 3, 25, 1, tzinfo=tz)
# x: datetime.datetime(2007, 3, 25, 1, 0, tzinfo=tzfile('/usr/share/zoneinfo/Europe/London'))
y = dt.fromtimestamp(int(x.strftime('%s')), tz)
# y: datetime.datetime(2007, 3, 25, 0, 0, tzinfo=tzfile('/usr/share/zoneinfo/Europe/London'))
assert x == y # This failsHowever if you use a new tz: gettz('Europe/London') or copy the existing one above, the equality comparison works:
z = dt.fromtimestamp(int(x.strftime('%s')), copy.copy(tz))
# z: datetime.datetime(2007, 3, 25, 0, 0, tzinfo=tzfile('/usr/share/zoneinfo/Europe/London'))
assert x == z # This passesThis is surprising, as the only difference is the re-use of the tzfile in the first instance. I would have though tzfile objects are immutable?
x == y
>>> False
x == z
>>> True
y == z
>>> TrueGiven both datetimes represent the same ms-since-epoch instant I would expect both assertions to pass.