Commit cf2f9c02 authored by Amos Latteier's avatar Amos Latteier

Changed pytz support not to check for the presence of pytz. We know pytz

will be present. Changes as per Andreas's request.
parent a5ca27d7
......@@ -173,9 +173,9 @@ Zope Changes
view to work. (patch by Sidnei da Silva from Enfold,
integration by Martijn Faassen (Startifact) for Infrae)
- DateTime now uses pytz for time zone data if available. This
means support for more time zones and up to date daylight
saving time information.
- DateTime now uses pytz for time zone data. This means support
for more time zones and up to date daylight saving time
information.
Bugs Fixed
......
......@@ -22,11 +22,7 @@ from datetime import datetime
from interfaces import IDateTime
from interfaces import DateTimeError, SyntaxError, DateError, TimeError
from zope.interface import implements
try:
from pytz_support import PytzCache
except ImportError:
# pytz not available, use legacy timezone support
PytzCache = None
from pytz_support import PytzCache
default_datefmt = None
......@@ -992,11 +988,7 @@ class DateTime:
# For backward compatibility only:
_isDST = localtime(time())[8]
_localzone = _isDST and _localzone1 or _localzone0
if PytzCache is not None:
_tzinfo = PytzCache(_cache())
else:
_tzinfo = _cache()
def localZone(self, ltm=None):
'''Returns the time zone on the given date. The time zone
......@@ -2049,6 +2041,5 @@ class strftimeFormatter:
# Module methods
def Timezones():
"""Return the list of recognized timezone names"""
if PytzCache is not None:
return list(PytzCache(_cache())._zlst)
return _cache._zlst
Pytz Support
============
If the pytz package is importable, it will be used for time zone
information, otherwise, DateTime's own time zone database is used. The
Allows the pytz package to be used for time zone information. The
advantage of using pytz is that it has a more complete and up to date
time zone and daylight savings time database.
This test assumes that pytz is available.
>>> import pytz
Usage
-----
If pytz is available, then DateTime will use it. You don't have to do
anything special to make it work.
You don't have to do anything special to make it work.
>>> from DateTime import DateTime, Timezones
>>> d = DateTime('March 11, 2007 US/Eastern')
......@@ -53,9 +48,9 @@ Let's compare this to 2006.
-18000
Time Zones
----------
When pytz is available, DateTime can use its large database of time
zones. Here are some examples:
---------
DateTime can use pytz's large database of time zones. Here are some
examples:
>>> d = DateTime('Pacific/Kwajalein')
>>> d = DateTime('America/Shiprock')
......@@ -75,13 +70,12 @@ the pytz database.
>>> d = DateTime('iceland')
These time zones use DateTimes database. So it's preferable to use the
official time zone name when you have pytz installed.
official time zone name.
One trickiness is that DateTime supports some zone name
abbreviations. Some of these map to pytz names, so when pytz is
present these abbreviations will give you time zone date from
pytz. Notable among abbreviations that work this way are 'est', 'cst',
'mst', and 'pst'.
abbreviations. Some of these map to pytz names, so these abbreviations
will give you time zone date from pytz. Notable among abbreviations
that work this way are 'est', 'cst', 'mst', and 'pst'.
Let's verify that 'est' picks up the 2007 daylight savings time changes.
......@@ -115,7 +109,7 @@ The following are tests of internal components.
Cache
~~~~~
When pytz is present, the DateTime class uses a different time zone cache.
The DateTime class uses a new time zone cache.
>>> DateTime._tzinfo #doctest: +ELLIPSIS
<DateTime.pytz_support.PytzCache instance at ...>
......
......@@ -509,20 +509,12 @@ class DateTimeTests(unittest.TestCase):
def test_suite():
from zope.testing import doctest
try:
# if pytz is available include a test for it
import pytz
return unittest.TestSuite([
unittest.makeSuite(DateTimeTests),
doctest.DocFileSuite('DateTime.txt', package='DateTime'),
doctest.DocFileSuite('pytz.txt', package='DateTime'),
])
except ImportError:
return unittest.TestSuite([
unittest.makeSuite(DateTimeTests),
doctest.DocFileSuite('DateTime.txt', package='DateTime')
])
if __name__=="__main__":
unittest.main(defaultTest='test_suite')
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment