fromutc: dt.tzinfo is not self: pytz.timezone('UTC').fromutc(datetime.utcnow())

Steven D'Aprano steve+comp.lang.python at pearwood.info
Wed Oct 19 17:03:21 EDT 2011


On Wed, 19 Oct 2011 01:06:53 -0700, aspineux wrote:

> 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 ?


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



More information about the Python-list mailing list