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