[Zope3-dev] OT: pytz

Marius Gedminas mgedmin at b4net.lt
Tue Jul 25 12:58:21 EDT 2006


On Mon, Jul 24, 2006 at 01:08:39AM +0200, Florent Guillaume wrote:
> Sorry about the offtopic, but can anyone shed some light on this:
> 
> >>> import pytz
> >>> from datetime import datetime
> >>> tz = pytz.timezone('Europe/Paris'); print datetime(2006, 7, 1,  
> tzinfo=tz).utcoffset()
> 0:09:00
> I expected 1 hour, not 9 minutes???

Read pytz/README.txt.  You're not supposed to pass tzinfo to datetime.
You're supposed to write

  >>> tz = pytz.timezone('Europe/Paris')
  >>> print tz.localize(datetime(2006, 7, 1))
  2:00:00

As you can see, in summer the offset is 2 hours due to daylight savings.

The author of pytz claims that it is impossible to make datetime(...,
tzinfo=some_tz) do the right thing because of the way the datetime
module is designed.  This is all very sad.  :(

Also be careful and avoid expressions like

  >>> print datetime(2006, 7, 1).replace(tzinfo=tz).utcoffset()

> Am I to assume the pytz databases are buggy? I'm using a zope 3.3  
> checkout.

pytz gets its database from the public-domain Olson time zone database
that is very extensive and widely used.

See http://en.wikipedia.org/wiki/Zoneinfo

Marius Gedminas
-- 
Remember, drive defensively! And of course, the best defense is a good offense!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: Digital signature
Url : http://mail.zope.org/pipermail/zope3-dev/attachments/20060725/2e1ee1ff/attachment.bin


More information about the Zope3-dev mailing list