python - pytz: _utcoffset has a wrong value for Iran -
correct value:
>>> pytz.timezone('asia/tehran').utcoffset(datetime(2013, 1, 1)).total_seconds()/3600.0 3.5 >>> pytz.timezone('asia/tehran').utcoffset(datetime(2013, 1, 1)).total_seconds() 12600.0
incorrect value:
>>> pytz.timezone('asia/tehran')._utcoffset.total_seconds()/3600.0 3.433333333333333 >>> pytz.timezone('asia/tehran')._utcoffset.total_seconds() 12360.0
i wonder if _utcoffset
attribute used in utcoffset()
method, why method working while attribute wrong.
looks bug anyway.
nothing changes if replace asia/tehran
iran
>>> print pytz.version 2012c
os: linux mint 15 (olivia)
using python 2.7
let's see what's going on here:
>>> tz = pytz.timezone('asia/tehran') >>> tz <dsttzinfo 'asia/tehran' lmt+3:26:00 std>
this means timezone expressed in lmt - solar time. that's why see utcoffset of 12360 - no error here, it's calculated using different reference.
now if do:
>>> d = tz.localize(datetime(2013, 1, 1)) >>> d datetime.datetime(2013, 1, 1, 0, 0, tzinfo=<dsttzinfo 'asia/tehran' irst+3:30:00 std>) >>> d.utcoffset() datetime.timedelta(0, 12600)
the localize
method caused representation switch correct time zone used @ date , place, irst utcoffset of 12600 seconds.
and that's utcoffset
method of tzinfo object - localizes given datetime object , returns it's utcoffset.
likewise if do:
>>> d = datetime.now(tz) >>> d datetime.datetime(2013, 8, 15, 20, 46, 4, 705896, tzinfo=<dsttzinfo 'asia/tehran' irdt+4:30:00 dst>) >>> d.utcoffset() datetime.timedelta(0, 16200)
you'll datetime expressed in irdt because daylight saving time in effect in timezone.
Comments
Post a Comment