Commit 40f11577 authored by 's avatar

merged changes from Zope-2_7-branch

parent 303d014e
......@@ -12,7 +12,7 @@
##############################################################################
"""Encapsulation of date/time values"""
__version__='$Revision: 1.96 $'[11:-2]
__version__='$Revision: 1.97 $'[11:-2]
import os, re, math, DateTimeZone
......@@ -410,7 +410,7 @@ def safegmtime(t):
if isinstance(t_int, long):
raise OverflowError # Python 2.3 fix: int can return a long!
return gmtime(t_int)
except (IOError, OverflowError):
except (ValueError, OverflowError):
raise TimeError, 'The time %f is beyond the range ' \
'of this Python implementation.' % float(t)
......@@ -420,11 +420,10 @@ def safelocaltime(t):
t_int = int(t)
if isinstance(t_int, long):
raise OverflowError # Python 2.3 fix: int can return a long!
except OverflowError:
return localtime(t_int)
except (ValueError, OverflowError):
raise TimeError, 'The time %f is beyond the range ' \
'of this Python implementation.' % float(t)
rval = localtime(t_int)
return rval
def _tzoffset2rfc822zone(seconds):
"""Takes an offset, such as from _tzoffset(), and returns an rfc822
......@@ -891,6 +890,11 @@ class DateTime:
yr = ((yr - 1970) % 28) + 1970
x = _calcDependentSecond2(yr,mo,dy,hr,mn,sc)
nearTime = x - fsetAtEpoch - long(EPOCH) + 86400L + ms
# nearTime might still be negative if we are east of Greenwich.
# But we can asume on 1969/12/31 were no timezone changes.
nearTime = max(0, nearTime)
ltm = safelocaltime(nearTime)
tz = self.localZone(ltm)
return tz
......
......@@ -245,10 +245,8 @@ class DateTimeTests(unittest.TestCase):
dt = DateTime('Tue, 24 Jul 2001 09:41:03 +0425')
self.assertEqual(dt.tzoffset(), 15900)
def testISO8601(self):
''' iso 8601 dates '''
from DateTime.DateTime import SyntaxError
ref0 = DateTime('2002/5/2 8:00am GMT')
ref1 = DateTime('2002/5/2 8:00am US/Eastern')
......@@ -264,10 +262,10 @@ class DateTimeTests(unittest.TestCase):
dgood = '2002-05-02'
tgood = 'T08:00:00-04:00'
for dbad in '2002-5-2', '2002-10-2', '2002-2-10', '02-2-10':
self.assertRaises(SyntaxError, DateTime, dbad)
self.assertRaises(SyntaxError, DateTime, dbad + tgood)
self.assertRaises(DateTime.SyntaxError, DateTime, dbad)
self.assertRaises(DateTime.SyntaxError, DateTime, dbad + tgood)
for tbad in '08:00', 'T8:00': #, 'T08:00Z-04:00':
self.assertRaises(SyntaxError, DateTime, dgood + tbad)
self.assertRaises(DateTime.SyntaxError, DateTime, dgood + tbad)
def testJulianWeek(self):
""" check JulianDayWeek function """
......@@ -329,6 +327,14 @@ class DateTimeTests(unittest.TestCase):
d_int = DateTime("%d/%d/%d" % (day,month,year), datefmt="international")
self.assertEqual(d_us, d_int)
def test_calcTimezoneName(self):
timezone_dependent_epoch = 2177452800L
try:
DateTime()._calcTimezoneName(timezone_dependent_epoch, 0)
except DateTime.TimeError:
self.fail('Zope Collector issue #484 (negative time bug): '
'TimeError raised')
def test_suite():
return unittest.makeSuite(DateTimeTests)
......
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