Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > fromutc: dt.tzinfo is not self: pytz.timezone('UTC').fromutc(datetime.utcnow())

Reply
Thread Tools

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

 
 
aspineux
Guest
Posts: n/a
 
      10-19-2011
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 ?

 
Reply With Quote
 
 
 
 
Chris Rebert
Guest
Posts: n/a
 
      10-19-2011
On Wed, Oct 19, 2011 at 1:06 AM, aspineux <(E-Mail Removed)> 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 ?


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
 
Reply With Quote
 
 
 
 
Steven D'Aprano
Guest
Posts: n/a
 
      10-19-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
 
Reply With Quote
 
aspineux
Guest
Posts: n/a
 
      10-21-2011
On Oct 19, 11:03*pm, Steven D'Aprano <steve
(E-Mail Removed)> wrote:
> 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.


Done

https://bugs.launchpad.net/pytz/+bug/879480

>
> --
> Steven


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
To be not, or not to be not? Ruby Freak Ruby 2 09-23-2008 08:04 AM
Why not 'foo = not f' instead of 'foo = (not f or 1) and 0'? Kristian Domke Python 11 01-23-2008 07:27 PM
'' is not a valid name. Make sure that it does not include invalid characters or punctuation and that it is not too long. rote ASP .Net 2 01-23-2008 03:07 PM
Cisco 3640 3620 3600 not detecting, not enabling, not working: NM-2FE2W Taki Soho Cisco 0 09-22-2004 07:28 AM
maintaining control with cookies (not strictly an ASP or even server side question. But not not either) Stephanie Stowe ASP General 2 04-07-2004 04:23 PM



Advertisments