python - Why doesn't pytz localize() produce a datetime object with tzinfo matching the tz object that localized it? -
is there can help me understand what's going on here?
import pytz datetime import datetime tz = pytz.timezone('europe/berlin') print repr(tz) # <dsttzinfo 'europe/berlin' lmt+0:53:00 std> dt = datetime(2011, 1, 3, 18, 40) result = tz.localize(dt) print repr(result.tzinfo) # <dsttzinfo 'europe/berlin' cet+1:00:00 std> assert result.tzinfo == tz, "why aren't these same timezone?"
my understanding localize()
method on pytz timezone object take naive datetime object, , add together tzinfo
property matches timezone object performing localization. not appear happening in case.
clearly, there's i'm misunderstanding timezones, or way pytz handles timezones. can explain?
they are same time zone - "europe/berlin"
.
when printing them, output includes abbreviation , offset applies @ particular point in time.
if examine the tz info sources, you'll see:
class="lang-none prettyprint-override"># zone name gmtoff rules format [until] zone europe/berlin 0:53:28 - lmt 1893 apr 1:00 c-eur ce%st 1945 may 24 2:00 1:00 sovietzone ce%st 1946 1:00 federal republic of germany ce%st 1980 1:00 european union ce%st
so appear when time zone has not localized datetime, uses first entry.
it appear pytz doesn't retain 28 seconds original local mean time deviation - doesn't matter unless working dates in berlin before apr 1893.
python datetime timezone pytz tzinfo
No comments:
Post a Comment