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

Discussion in 'Python' started by aspineux, Oct 19, 2011.

  1. aspineux

    aspineux Guest

    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 ?
     
    aspineux, Oct 19, 2011
    #1
    1. Advertising

  2. aspineux

    Chris Rebert Guest

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

    On Wed, Oct 19, 2011 at 1:06 AM, 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 ?


    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
     
    Chris Rebert, Oct 19, 2011
    #2
    1. Advertising

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

    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
     
    Steven D'Aprano, Oct 19, 2011
    #3
  4. aspineux

    aspineux Guest

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

    On Oct 19, 11:03 pm, Steven D'Aprano <steve
    > 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
     
    aspineux, Oct 21, 2011
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Elizabeth Harmon

    Datetime.UTCNow Problems

    Elizabeth Harmon, Dec 8, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    2,391
    Elizabeth Harmon
    Dec 8, 2004
  2. =?Utf-8?B?aGVuaw==?=

    Covert UTC String to UTC Datetime

    =?Utf-8?B?aGVuaw==?=, May 7, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    18,815
    Egbert Nierop \(MVP for IIS\)
    May 7, 2006
  3. Justin Voelker
    Replies:
    2
    Views:
    282
    Dr J R Stockton
    Dec 2, 2008
  4. Skip Montanaro

    pytz question: GMT vs. UTC

    Skip Montanaro, Jan 29, 2014, in forum: Python
    Replies:
    25
    Views:
    196
    Grant Edwards
    Feb 2, 2014
  5. Chris Angelico

    Re: pytz question: GMT vs. UTC

    Chris Angelico, Jan 29, 2014, in forum: Python
    Replies:
    0
    Views:
    75
    Chris Angelico
    Jan 29, 2014
Loading...

Share This Page