Question

I'm using the pytz library (django timezone) to handle timezones on my website, and I noticed a wrong offset only for Africa/Casablanca, here is the example:

In [1]: import datetime

In [2]: import pytz

In [3]: from django.utils.dateformat import format

In [4]: paris = pytz.timezone("Europe/Paris")

In [5]: paris.localize(datetime.datetime.now(), is_dst=True)
Out[5]: datetime.datetime(2014, 4, 25, 11, 25, 9, 473706, tzinfo=<DstTzInfo 'Europe/Paris' CEST+2:00:00 DST>)

In [6]: casablanca = pytz.timezone("Africa/Casablanca")

In [7]: casablanca.localize(datetime.datetime.now(), is_dst=True)
Out[7]: datetime.datetime(2014, 4, 25, 11, 25, 23, 416349, tzinfo=<DstTzInfo 'Africa/Casablanca' WET0:00:00 STD>)

In [8]: format(casablanca.localize(datetime.datetime.now(), is_dst=True), "O") == "+0100"
Out[8]: False

Notice that Morocco is on DST since the April 1st.

Since we have a large number of visitors from Morocco it's a very frustrating issue.

Any suggestions would be greatly appreciated, Thanks in advance.

(OS: Ubuntu 12.04)

Was it helpful?

Solution

I think you just have an old version of pytz. I ran your code using the latest version and it shows the correct values.

Morocco changed it's DST rules for 2014. Details here and here.

This was put into version 2013g of the time zone database. See the Latest Versions section of the pytz docs for updating information.

In general, if you are serving a global audience, you should monitor the pytz atom feed, or the IANA announcements mailing list, and plan on updating several times per year.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top