Discussion:
fromutc: dt.tzinfo is not self: pytz.timezone('UTC').fromutc(datetime.utcnow())
(too old to reply)
aspineux
2011-10-19 08:06:53 UTC
Permalink
hi
import pytz
from datetime import datetime
pytz.timezone('GMT0').fromutc(datetime.utcnow())
datetime.datetime(2011, 10, 19, 7, 54, 45, 579125,
tzinfo=<StaticTzInfo 'GMT0'>)
pytz.timezone('UTC').fromutc(datetime.utcnow())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: fromutc: dt.tzinfo is not self
pytz.timezone('Europe/Brussels').fromutc(datetime.utcnow())
datetime.datetime(2011, 10, 19, 9, 55, 47, 787937, tzinfo=<DstTzInfo
'Europe/Brussels' CEST+2:00:00 DST>)

Why does UTC fail ?
Bug or feature ?
Chris Rebert
2011-10-19 08:32:58 UTC
Permalink
Post by aspineux
hi
import pytz
from datetime import datetime
pytz.timezone('GMT0').fromutc(datetime.utcnow())
datetime.datetime(2011, 10, 19, 7, 54, 45, 579125,
tzinfo=<StaticTzInfo 'GMT0'>)
 pytz.timezone('UTC').fromutc(datetime.utcnow())
 File "<stdin>", line 1, in <module>
ValueError: fromutc: dt.tzinfo is not self
pytz.timezone('Europe/Brussels').fromutc(datetime.utcnow())
datetime.datetime(2011, 10, 19, 9, 55, 47, 787937, tzinfo=<DstTzInfo
'Europe/Brussels' CEST+2:00:00 DST>)
Why does UTC fail ?
Bug or feature ?
Dunno, but it might be worth noting that the examples in the pytz docs
don't use .fromutc(). Have you tried using .localize() instead? Or
specifically in the case of UTC,
datetime.utcnow().replace(tzinfo=pytz.utc) ?

Cheers,
Chris
Steven D'Aprano
2011-10-19 21:03:21 UTC
Permalink
hi
import pytz
from datetime import datetime
pytz.timezone('GMT0').fromutc(datetime.utcnow())
datetime.datetime(2011, 10, 19, 7, 54, 45, 579125, tzinfo=<StaticTzInfo
'GMT0'>)
pytz.timezone('UTC').fromutc(datetime.utcnow())
File "<stdin>", line 1, in <module>
ValueError: fromutc: dt.tzinfo is not self
pytz.timezone('Europe/Brussels').fromutc(datetime.utcnow())
datetime.datetime(2011, 10, 19, 9, 55, 47, 787937, tzinfo=<DstTzInfo
'Europe/Brussels' CEST+2:00:00 DST>)
Why does UTC fail ?
Bug or feature ?
Looks like a bug to me. But I'm not an expert on pytz. Perhaps you should
report it back to the package author.
--
Steven
aspineux
2011-10-21 16:06:07 UTC
Permalink
On Oct 19, 11:03 pm, Steven D'Aprano <steve
Post by Steven D'Aprano
hi
import pytz
from datetime import datetime
pytz.timezone('GMT0').fromutc(datetime.utcnow())
datetime.datetime(2011, 10, 19, 7, 54, 45, 579125, tzinfo=<StaticTzInfo
'GMT0'>)
 pytz.timezone('UTC').fromutc(datetime.utcnow())
  File "<stdin>", line 1, in <module>
ValueError: fromutc: dt.tzinfo is not self
pytz.timezone('Europe/Brussels').fromutc(datetime.utcnow())
datetime.datetime(2011, 10, 19, 9, 55, 47, 787937, tzinfo=<DstTzInfo
'Europe/Brussels' CEST+2:00:00 DST>)
Why does UTC fail ?
Bug or feature ?
Looks like a bug to me. But I'm not an expert on pytz. Perhaps you should
report it back to the package author.
Done

https://bugs.launchpad.net/pytz/+bug/879480
Post by Steven D'Aprano
--
Steven
Loading...