Commit 40f11577 authored by 's avatar

merged changes from Zope-2_7-branch

parent 303d014e
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
############################################################################## ##############################################################################
"""Encapsulation of date/time values""" """Encapsulation of date/time values"""
__version__='$Revision: 1.96 $'[11:-2] __version__='$Revision: 1.97 $'[11:-2]
import os, re, math, DateTimeZone import os, re, math, DateTimeZone
...@@ -409,8 +409,8 @@ def safegmtime(t): ...@@ -409,8 +409,8 @@ def safegmtime(t):
t_int = int(t) t_int = int(t)
if isinstance(t_int, long): if isinstance(t_int, long):
raise OverflowError # Python 2.3 fix: int can return a long! raise OverflowError # Python 2.3 fix: int can return a long!
return gmtime(t_int) return gmtime(t_int)
except (IOError, OverflowError): except (ValueError, OverflowError):
raise TimeError, 'The time %f is beyond the range ' \ raise TimeError, 'The time %f is beyond the range ' \
'of this Python implementation.' % float(t) 'of this Python implementation.' % float(t)
...@@ -420,11 +420,10 @@ def safelocaltime(t): ...@@ -420,11 +420,10 @@ def safelocaltime(t):
t_int = int(t) t_int = int(t)
if isinstance(t_int, long): if isinstance(t_int, long):
raise OverflowError # Python 2.3 fix: int can return a 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 ' \ raise TimeError, 'The time %f is beyond the range ' \
'of this Python implementation.' % float(t) 'of this Python implementation.' % float(t)
rval = localtime(t_int)
return rval
def _tzoffset2rfc822zone(seconds): def _tzoffset2rfc822zone(seconds):
"""Takes an offset, such as from _tzoffset(), and returns an rfc822 """Takes an offset, such as from _tzoffset(), and returns an rfc822
...@@ -891,6 +890,11 @@ class DateTime: ...@@ -891,6 +890,11 @@ class DateTime:
yr = ((yr - 1970) % 28) + 1970 yr = ((yr - 1970) % 28) + 1970
x = _calcDependentSecond2(yr,mo,dy,hr,mn,sc) x = _calcDependentSecond2(yr,mo,dy,hr,mn,sc)
nearTime = x - fsetAtEpoch - long(EPOCH) + 86400L + ms 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) ltm = safelocaltime(nearTime)
tz = self.localZone(ltm) tz = self.localZone(ltm)
return tz return tz
...@@ -1028,7 +1032,7 @@ class DateTime: ...@@ -1028,7 +1032,7 @@ class DateTime:
else: else:
day=ints[0] day=ints[0]
month=ints[1] month=ints[1]
elif ints[0] <= 12: elif ints[0] <= 12:
month=ints[0] month=ints[0]
day=ints[1] day=ints[1]
...@@ -1489,7 +1493,7 @@ class DateTime: ...@@ -1489,7 +1493,7 @@ class DateTime:
def rfc822(self): def rfc822(self):
"""Return the date in RFC 822 format""" """Return the date in RFC 822 format"""
tzoffset = _tzoffset2rfc822zone(_tzoffset(self._tz, self._t)) tzoffset = _tzoffset2rfc822zone(_tzoffset(self._tz, self._t))
return '%s, %2.2d %s %d %2.2d:%2.2d:%2.2d %s' % ( return '%s, %2.2d %s %d %2.2d:%2.2d:%2.2d %s' % (
self._aday,self._day,self._amon,self._year, self._aday,self._day,self._amon,self._year,
self._hour,self._minute,self._nearsec,tzoffset) self._hour,self._minute,self._nearsec,tzoffset)
...@@ -1686,8 +1690,8 @@ class DateTime: ...@@ -1686,8 +1690,8 @@ class DateTime:
if fields[5]: seconds = int(fields[5]) if fields[5]: seconds = int(fields[5])
if fields[6]: seconds = seconds+float(fields[6]) if fields[6]: seconds = seconds+float(fields[6])
z = fields[7] z = fields[7]
if z and z.startswith('Z'): if z and z.startswith('Z'):
# Waaaa! This is wrong, since 'Z' and '+HH:MM' # Waaaa! This is wrong, since 'Z' and '+HH:MM'
# are supposed to be mutually exclusive. # are supposed to be mutually exclusive.
# It's only here to prevent breaking 2.7 beta. # It's only here to prevent breaking 2.7 beta.
......
...@@ -232,11 +232,11 @@ class DateTimeTests(unittest.TestCase): ...@@ -232,11 +232,11 @@ class DateTimeTests(unittest.TestCase):
# A negative numerical timezone # A negative numerical timezone
dt = DateTime('Tue, 24 Jul 2001 09:41:03 -0400') dt = DateTime('Tue, 24 Jul 2001 09:41:03 -0400')
self.assertEqual(dt.tzoffset(), -14400) self.assertEqual(dt.tzoffset(), -14400)
# A positive numerical timzone # A positive numerical timzone
dt = DateTime('Tue, 6 Dec 1966 01:41:03 +0200') dt = DateTime('Tue, 6 Dec 1966 01:41:03 +0200')
self.assertEqual(dt.tzoffset(), 7200) self.assertEqual(dt.tzoffset(), 7200)
# A negative numerical timezone with minutes. # A negative numerical timezone with minutes.
dt = DateTime('Tue, 24 Jul 2001 09:41:03 -0637') dt = DateTime('Tue, 24 Jul 2001 09:41:03 -0637')
self.assertEqual(dt.tzoffset(), -23820) self.assertEqual(dt.tzoffset(), -23820)
...@@ -244,11 +244,9 @@ class DateTimeTests(unittest.TestCase): ...@@ -244,11 +244,9 @@ class DateTimeTests(unittest.TestCase):
# A positive numerical timezone with minutes. # A positive numerical timezone with minutes.
dt = DateTime('Tue, 24 Jul 2001 09:41:03 +0425') dt = DateTime('Tue, 24 Jul 2001 09:41:03 +0425')
self.assertEqual(dt.tzoffset(), 15900) self.assertEqual(dt.tzoffset(), 15900)
def testISO8601(self): def testISO8601(self):
''' iso 8601 dates ''' ''' iso 8601 dates '''
from DateTime.DateTime import SyntaxError
ref0 = DateTime('2002/5/2 8:00am GMT') ref0 = DateTime('2002/5/2 8:00am GMT')
ref1 = DateTime('2002/5/2 8:00am US/Eastern') ref1 = DateTime('2002/5/2 8:00am US/Eastern')
...@@ -264,10 +262,10 @@ class DateTimeTests(unittest.TestCase): ...@@ -264,10 +262,10 @@ class DateTimeTests(unittest.TestCase):
dgood = '2002-05-02' dgood = '2002-05-02'
tgood = 'T08:00:00-04:00' tgood = 'T08:00:00-04:00'
for dbad in '2002-5-2', '2002-10-2', '2002-2-10', '02-2-10': for dbad in '2002-5-2', '2002-10-2', '2002-2-10', '02-2-10':
self.assertRaises(SyntaxError, DateTime, dbad) self.assertRaises(DateTime.SyntaxError, DateTime, dbad)
self.assertRaises(SyntaxError, DateTime, dbad + tgood) self.assertRaises(DateTime.SyntaxError, DateTime, dbad + tgood)
for tbad in '08:00', 'T8:00': #, 'T08:00Z-04:00': 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): def testJulianWeek(self):
""" check JulianDayWeek function """ """ check JulianDayWeek function """
...@@ -329,6 +327,14 @@ class DateTimeTests(unittest.TestCase): ...@@ -329,6 +327,14 @@ class DateTimeTests(unittest.TestCase):
d_int = DateTime("%d/%d/%d" % (day,month,year), datefmt="international") d_int = DateTime("%d/%d/%d" % (day,month,year), datefmt="international")
self.assertEqual(d_us, d_int) 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(): def test_suite():
return unittest.makeSuite(DateTimeTests) 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