Commit f4a547f4 authored by Jim Fulton's avatar Jim Fulton

The DateTime module was changed to no longer import the string module,

but one of the uses of string.atoi wasn't fixed.  There also wasn't a
test for this. :(

Fixed bug in handling numneric time-zone offsets. We need to subtract,
rather than add the offset, since the offset is the offset of the
local time from UT, not the other way around.
parent d8697c02
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
############################################################################## ##############################################################################
"""Encapsulation of date/time values""" """Encapsulation of date/time values"""
__version__='$Revision: 1.73 $'[11:-2] __version__='$Revision: 1.74 $'[11:-2]
import re,sys, os, math, DateTimeZone import re,sys, os, math, DateTimeZone
...@@ -34,11 +34,8 @@ to_month=tm[yr%4==0 and (yr%100!=0 or yr%400==0)][mo] ...@@ -34,11 +34,8 @@ to_month=tm[yr%4==0 and (yr%100!=0 or yr%400==0)][mo]
EPOCH =(to_year+to_month+dy+(hr/24.0+mn/1440.0+sc/86400.0))*86400 EPOCH =(to_year+to_month+dy+(hr/24.0+mn/1440.0+sc/86400.0))*86400
jd1901 =2415385L jd1901 =2415385L
numericTimeZoneMatch=re.compile(r'[+-][0-9][0-9][0-9][0-9]').match #TS numericTimeZoneMatch=re.compile(r'[+-][0-9][0-9][0-9][0-9]').match #TS
class _timezone: class _timezone:
def __init__(self,data): def __init__(self,data):
self.name,self.timect,self.typect, \ self.name,self.timect,self.typect, \
...@@ -364,7 +361,7 @@ def _tzoffset(tz, t): ...@@ -364,7 +361,7 @@ def _tzoffset(tz, t):
return DateTime._tzinfo[tz].info(t)[0] return DateTime._tzinfo[tz].info(t)[0]
except: except:
if numericTimeZoneMatch(tz) is not None: if numericTimeZoneMatch(tz) is not None:
return atoi(tz[1:3])*3600+atoi(tz[3:5])*60 return -int(tz[1:3])*3600-int(tz[3:5])*60
else: else:
return 0 # ?? return 0 # ??
...@@ -918,6 +915,7 @@ class DateTime: ...@@ -918,6 +915,7 @@ class DateTime:
# Check for and skip day of week: # Check for and skip day of week:
if DayOfWeekNames.has_key(s): if DayOfWeekNames.has_key(s):
continue continue
raise self.SyntaxError, st raise self.SyntaxError, st
day=None day=None
......
...@@ -189,6 +189,14 @@ class DateTimeTests (unittest.TestCase): ...@@ -189,6 +189,14 @@ class DateTimeTests (unittest.TestCase):
assert ddays == 3000000L, ddays assert ddays == 3000000L, ddays
def test_tzoffset(self):
'''Test time-zone given as an offset
'''
from time import gmtime
dt = DateTime('Tue, 24 Jul 2001 09:41:03 -0400')
self.assertEqual(gmtime(dt.timeTime())[:6],
(2001,7,24,13,41,3))
def testISO8601(self): def testISO8601(self):
''' iso 8601 dates ''' ''' 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