Commit ee0ccbb8 authored by Lennart Regebro's avatar Lennart Regebro

Merge with HEAD.

#740: _tzoffset handled positive numerical offsets incorrectly. This has been fixed. A large set of tests for different cases has been added, and for the purpose of those tests DateTime has a new feature: A tzoffset() method.
parent 6135cd85
......@@ -39,9 +39,16 @@ Zope Changes
Zope 2.6.1 beta 2
Features added
- DateTime objects now have a tzoffset() method that returns the objects
timezones offset from GMT in seconds.
Bugs Fixed
- Collector #740: DateTime now handles positive numerical timezones correcly.
- Collector #763: There was no error when you had a sendmail-tag
without specifying a mailhost or smpthost. Also added a missing import.
......
......@@ -12,7 +12,7 @@
##############################################################################
"""Encapsulation of date/time values"""
__version__='$Revision: 1.83 $'[11:-2]
__version__='$Revision: 1.84 $'[11:-2]
import re, math, DateTimeZone
......@@ -370,7 +370,7 @@ def _tzoffset(tz, t):
return DateTime._tzinfo[tz].info(t)[0]
except:
if numericTimeZoneMatch(tz) is not None:
return -int(tz[1:3])*3600-int(tz[3:5])*60
return int(tz[0:3])*3600+int(tz[0]+tz[3:5])*60
else:
return 0 # ??
......@@ -1294,6 +1294,10 @@ class DateTime:
"""Return the timezone in which the object is represented."""
return self._tz
def tzoffset(self):
"""Return the timezone offset for the objects timezone."""
return _tzoffset(self._tz, self._t)
def year(self):
"""Return the calendar year of the object"""
return self._year
......
......@@ -212,9 +212,39 @@ class DateTimeTests(unittest.TestCase):
def test_tzoffset(self):
'''Test time-zone given as an offset'''
# GMT
dt = DateTime('Tue, 10 Sep 2001 09:41:03 GMT')
self.assertEqual(dt.tzoffset(), 0)
# Timezone by name, a timezone that hasn't got daylightsaving.
dt = DateTime('Tue, 2 Mar 2001 09:41:03 GMT+3')
self.assertEqual(dt.tzoffset(), 10800)
# Timezone by name, has daylightsaving but is not in effect.
dt = DateTime('Tue, 21 Jan 2001 09:41:03 PST')
self.assertEqual(dt.tzoffset(), -28800)
# Timezone by name, with daylightsaving in effect
dt = DateTime('Tue, 24 Aug 2001 09:41:03 PST')
self.assertEqual(dt.tzoffset(), -25200)
# A negative numerical timezone
dt = DateTime('Tue, 24 Jul 2001 09:41:03 -0400')
self.assertEqual(time.gmtime(dt.timeTime())[:6],
(2001, 7, 24, 13, 41, 3))
self.assertEqual(dt.tzoffset(), -14400)
# A positive numerical timzone
dt = DateTime('Tue, 6 Dec 1966 01:41:03 +0200')
self.assertEqual(dt.tzoffset(), 7200)
# A negative numerical timezone with minutes.
dt = DateTime('Tue, 24 Jul 2001 09:41:03 -0637')
self.assertEqual(dt.tzoffset(), -23820)
# A positive numerical timezone with minutes.
dt = DateTime('Tue, 24 Jul 2001 09:41:03 +0425')
self.assertEqual(dt.tzoffset(), 15900)
def testISO8601(self):
''' iso 8601 dates '''
......
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