Datetime, pytz and strange offset

Discussion in 'Python' started by David Pratt, Dec 13, 2005.

  1. David Pratt

    David Pratt Guest

    Hi. I am creating a couple of small methods to help me manage time from
    UTC as standard but I am getting strange results.

    If I start with a datetime of 2005-12-12 14:30:00 in timezone
    'America/Halifax'
    and I want to turn this into a UTC representation.

    from datetime import datetime
    from pytz.reference import UTC
    import pytz

    fmt = '%Y-%m-%d %H:%M:%S %Z%z'
    tz = pytz.timezone('America/Halifax')
    dt = datetime(year=2005, month=12, day=11, hour=14, minute=30, second=0,
    microsecond=0, tzinfo=tz)
    print dt.strftime(fmt)

    This is giving me a strange offset of -0414 and LMT timezone.
    ie. 2005-12-12 14:30:00 LMT-0414
    I am not sure where this is coming from

    To get the utc equivalent using dt = dt.astimezone(UTC) I get this
    strange result which is obviously also not correct:
    # '2005-12-12 18:44:00 UTC+0000'

    If I do datetime.now instead with the same timezone I get the correct
    timezone and correct offset.

    ie.
    dt = datetime.now(tz=tz)
    # '2005-12-12 21:37:17 AST-0400'

    If I get now time from this as utc it is correct
    dt = dt.astimezone(UTC)
    # '2005-12-12 01:37:17 UTC+0000'

    If I do a different timezone of 'America/Vancouver'
    I get something appropriate for the 2:30 case

    tz = pytz.timezone('America/Vancouver')
    dt = datetime(year=2005, month=12, day=12, hour=14, minute=30, second=0,
    microsecond=0, tzinfo=tz)
    print dt.strftime(fmt)
    # 2005-12-12 20:30:00 PST-0800

    I am not sure why I am getting -0414 and LMT for 'America/Halifax'
    timezone? Is this a bug in the pytz package? Many thanks.

    Regards,
    David
    David Pratt, Dec 13, 2005
    #1
    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. Lance Riedel

    Translated Offset to Source Offset

    Lance Riedel, Oct 14, 2003, in forum: XML
    Replies:
    2
    Views:
    499
    Patrick TJ McPhee
    Oct 15, 2003
  2. Sanjay
    Replies:
    2
    Views:
    421
    Sanjay
    Jul 18, 2007
  3. Sanjay
    Replies:
    0
    Views:
    368
    Sanjay
    Jul 13, 2007
  4. aspineux
    Replies:
    3
    Views:
    265
    aspineux
    Oct 21, 2011
  5. Roy Smith
    Replies:
    4
    Views:
    267
    Roy Smith
    Jan 27, 2013
Loading...

Share This Page