download version 0.2 (~20k)
time zone data (~52k)
Python 2.3 defines a new datetime module which provide some great tools for handling date and time operation. The datetime module define the tzinfo protocol for handling time zone management but doesn't provide any concrete implementation by itself. The goal of this tz package is to provide a set of concrete tzinfo implementation.
Right now the package support only the tzinfo public domain database. The tzinfo database is used by Linux, xxxBSD and MacosX (and probably many other Unix flavors).
The goal of the tz package is to provide a unified API for the various
time zone database used by the platforms able to run Python.
>>> import datetime, tz >>> T = tz.timezone("Europe/Amsterdam") >>> dt1 = datetime.datetimetz(2003,1,1,12,0,0,tzinfo=T) >>> print dt1 2003-01-01 12:00:00+01:00 >>> print dt1.utcoffset() 1:00:00 >>> print dt1.tzname() CET >>> U = tz.timezone("America/Buenos_Aires") >>> dt2 = datetime.datetimetz(2003,1,1,12,0,0,tzinfo=U) >>> print dt2 2003-01-01 12:00:00-03:00 >>> print dt2.utcoffset() -1 day, 21:00:00 >>> print dt2.tzname() ART >>> print dt2-dt1 4:00:00
You can also use the local time zone
>>> import tz >>> l = tz.timezone("localtime")Or the obvious UTC time zone
>>> import tz >>> utc = tz.timezone("UTC")
Return a timezone object or raise a value error if the name argument isn't a valid timezone name for any backend available.
The timezone objects define the several methods required by the tzinfo protocol:
return offset of local time from UTC
return the timezone name corresponding to the datetime represented by dt.
return the daylight saving time offset.
See the datetime module documentation for more informations.
This database is used by many unixes flavors, so if you use a computer with an Unix os, there are great chances that the database is already installed in your system. If this is not the case (or if you are using an other os) the package will install a database extract. It contain a rather concequent subset of the database: the rules from 1970 for all the Olson files except 'backward', 'etcetera', 'leapseconds', 'pacificnew', 'solar87', 'solar88' and 'solar89', 'factory' and 'systemv', since these don't really provide any useful timezones.
Note that the installer won't be able to detect existing database if they are neither in the /usr/share/zoneinfo nor in the /usr/lib/zoneinfo directory. If your database is installed somewhere else, you will have to set the TZDIR environment variable or to provide the --tzdir option, to get it detected.
The module provide a timezone object witch act as a wrapper around a tzfile. This object provide all the methods defined by tzinfo and the following one:
method rulesrange(mini, maxi)
return the rules used to compute the gmt dates between min and max as tuple(local transition date, offset in minutes, zone abreviation, dst flag).
Time zones are named from the continent they belong to and by the name of the main town in the time zone.
This table provide some time zone samples. A text in the comment column mean that several time zone can apply to the country.
|AU||Australia||Australia/Sydney||New South Wales - most locations|
|NZ||New Zealand||Pacific/Auckland||most locations|
|US||United States||America/New_York||Eastern Time|
|localtime||The time zone used by your computer|
|UTC||Universal standard time|
|GMT||alias for UTC timezone|