[Zope-Checkins] CVS: Packages/DateTime - DateTime.py:1.92
Evan Simpson
cvs-admin at zope.org
Thu Nov 20 12:10:12 EST 2003
Update of /cvs-repository/Packages/DateTime
In directory cvs.zope.org:/tmp/cvs-serv9593/lib/python/DateTime
Modified Files:
DateTime.py
Log Message:
Mostly fixed Collector #1129. Badly formed ISO8601 dates are rejected,
except that 'Z' is still allowed in front of a '+/-HH:MM' timezone. I
left that in since it was used elsewhere in the code, and was probably
harmless, whereas the other parse problems caused dates like "2003-2-5"
to be accepted as valid and silently converted into "2003-01-01".
Also re-exposed the DateTime-specific exceptions as attributes of the
DateTime class. During their recent converted from strings to classes,
they were removed.
=== Packages/DateTime/DateTime.py 1.91 => 1.92 ===
--- Packages/DateTime/DateTime.py:1.91 Tue Nov 18 08:16:59 2003
+++ Packages/DateTime/DateTime.py Thu Nov 20 12:09:41 2003
@@ -497,6 +497,12 @@
then the current date/time is returned, represented in the
timezone of the local machine.
+ # Make class-specific exceptions available as attributes.
+ DateError = DateError
+ TimeError = TimeError
+ DateTimeError = DateTimeError
+ SyntaxError = SyntaxError
+
- If the function is invoked with a single string argument
which is a recognized timezone name, an object representing
the current time is returned, represented in the specified
@@ -1657,7 +1663,8 @@
hour=minute=seconds=hour_off=min_off=0
datereg = re.compile('([0-9]{4})(-([0-9][0-9]))?(-([0-9][0-9]))?')
- timereg = re.compile('([0-9]{2})(:([0-9][0-9]))?(:([0-9][0-9]))?(\.[0-9]{1,20})?')
+ timereg = re.compile('T([0-9]{2})(:([0-9][0-9]))?(:([0-9][0-9]))?(\.[0-9]{1,20})?')
+ zonereg = re.compile('([+-][0-9][0-9])(:([0-9][0-9]))')
# Date part
@@ -1666,21 +1673,33 @@
if fields[1]: year = int(fields[1])
if fields[3]: month = int(fields[3])
if fields[5]: day = int(fields[5])
+ t = fields[6]
+ if t:
+ if not fields[5]:
+ # Specifying time requires specifying a day.
+ raise IndexError
- if s.find('T')>-1:
- fields = timereg.split(s[s.find('T')+1:])
+ fields = timereg.split(t)
if fields[1]: hour = int(fields[1])
if fields[3]: minute = int(fields[3])
if fields[5]: seconds = int(fields[5])
if fields[6]: seconds = seconds+float(fields[6])
-
- if s.find('Z')>-1:
- pass
-
- if s[-3]==':' and s[-6] in ['+','-']:
- hour_off = int(s[-6:-3])
- min_off = int(s[-2:])
+ z = fields[7]
+
+ if z and z.startswith('Z'):
+ # Waaaa! This is wrong, since 'Z' and '+HH:MM'
+ # are supposed to be mutually exclusive.
+ # It's only here to prevent breaking 2.7 beta.
+ z = z[1:]
+
+ if z:
+ fields = zonereg.split(z)
+ hour_off = int(fields[1])
+ min_off = int(fields[3])
+ if fields[4]:
+ # Garbage after time zone
+ raise IndexError
return year,month,day,hour,minute,seconds,'GMT%+03d%02d' % (hour_off,min_off)
More information about the Zope-Checkins
mailing list