Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Datetime, pytz and strange offset

Reply
Thread Tools

Datetime, pytz and strange offset

 
 
David Pratt
Guest
Posts: n/a
 
      12-13-2005
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
 
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
Comparing offset-aware and offset-naive datetimes? Roy Smith Python 4 01-27-2013 03:17 PM
pytz giving incorrect offset and timezone Sanjay Python 2 07-18-2007 12:23 PM
pytz giving incorrect offset and timezone Sanjay Python 0 07-13-2007 11:55 AM
Matplotlib, py2exe and pytz scott Python 2 02-20-2005 03:10 AM
Translated Offset to Source Offset Lance Riedel XML 2 10-15-2003 03:04 PM



Advertisments