AX Semantics Developer Blog
  • Home
  • Categories
  • Tags
  • Archives

Pytz and strange timezones

Timezones are not easy. But with the pytz release 2014.3 it got even more insane.

For example:

>>> import pytz
>>> pytz.timezone('Europe/Berlin')
<DstTzInfo 'Europe/Berlin' LMT+0:53:00 STD>

LMT is for local mean time which was the timezone system till 1893.

After version 2014.3 of pytz you should not use tzinfo to set timezone:

>>> import pytz
>>> from datetime import datetime
>>> datetime(2014, 8, 29, 18, 0, tzinfo=pytz.timezone('Europe/Berlin'))
datetime(2014, 8, 29, 18, 0, tzinfo=<DstTzInfo 'Europe/Berlin' LMT+0:53:00 STD>)

now you really should use .localize() of your timezone object:

>>> import pytz
>>> from datetime import datetime
>>> pytz.timezone('Europe/Berlin').localize(datetime(2014, 8, 29, 18, 0))
datetime(2014, 8, 29, 18, 0, tzinfo=<DstTzInfo 'Europe/Berlin' CEST+2:00:00 DST>)

for more information see http://stackoverflow.com/questions/24359540/why-doesnt-pytz-localize-produce-a-datetime-object-with-tzinfo-matching-the-t

Tell us what you think about this. Is something unclear? Do you have questions or ideas? Leave your comments below.

Comments
comments powered by Disqus

  • « How to turn off the alarm LED on Juniper Switches (e.g. EX2200-C)
  • Switch "Insert" and "End" key on a ThinkPad x240 with Ubuntu »

Published

Jan 28, 2015

Category

Techstack

Tags

  • python 8
  • timezones 1
  • AX Semantics Developer Blog - Technical stuff and learnings we had while developing the AX environment
  • Powered by Pelican. Theme: Elegant by Talha Mansoor