pytz and Python timezones

Irmen de Jong irmen.NOSPAM at xs4all.nl
Sat Jun 11 08:24:37 EDT 2016


On 11-6-2016 13:37, Johannes Bauer wrote:
> Hi there,
> 
> first off, let me admit that I have a hard time comprehensively wrapping
> my head around timezones. Everything around them is much more
> complicated than it seems, IMO.

They might not seem complicated, but actually they are. Mindbogglingly so:
https://www.youtube.com/watch?v=-5wpm-gesOY

> pytz.timezone("Europe/Berlin").localize(datetime.datetime(2016,1,1))
> 
> Gives me the expected result of:
> 
> datetime.datetime(2016, 1, 1, 0, 0, tzinfo=<DstTzInfo 'Europe/Berlin'
> CET+1:00:00 STD>)
> 
> Can someone explain what's going on here and why I end up with the weird
> "00:53" timezone? Is this a bug or am I doing things wrong?

I ran into the same issue a while ago and have since accepted that "the right way to do
it" is indeed not passing a tzinfo into the datetime constructor, but to always use the
second form with tz.localize(datetime).
I suppose it is a problem (not so much a bug) caused by the way timezones are done
internally in pytz and/or datetime but haven't looked into the details. Mostly because
of what is said the video I linked above :)

Irmen



More information about the Python-list mailing list