[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[minion-cvs] Add and test parsing support for new date and time form...



Update of /home/minion/cvsroot/src/minion/lib/mixminion
In directory moria.mit.edu:/tmp/cvs-serv10109/lib/mixminion

Modified Files:
	test.py Config.py 
Log Message:
Add and test parsing support for new date and time formats.  (We dont generate them till 006).

Index: test.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/test.py,v
retrieving revision 1.122
retrieving revision 1.123
diff -u -d -r1.122 -r1.123
--- test.py	21 Jun 2003 07:29:32 -0000	1.122
+++ test.py	21 Jun 2003 21:47:50 -0000	1.123
@@ -3590,9 +3590,13 @@
         self.assertEquals(time.gmtime(tm)[:6], (2002,5,30,0,0,0))
         tm = C._parseDate("2000/01/01")
         self.assertEquals(time.gmtime(tm)[:6], (2000,1,1,0,0,0))
+        tm = C._parseDate("2000-05-03")
+        self.assertEquals(time.gmtime(tm)[:6], (2000,5,3,0,0,0))
         # Time
         tm = C._parseTime("2001/12/25 06:15:10")
         self.assertEquals(time.gmtime(tm)[:6], (2001,12,25,6,15,10))
+        tm = C._parseTime("2001-12-25 06:15:10.623")
+        self.assertEquals(time.gmtime(tm)[:6], (2001,12,25,6,15,10))
         # nicknames
         self.assertEquals(C._parseNickname("Mrs.Premise"), "Mrs.Premise")
         # Filenames
@@ -3648,9 +3652,13 @@
         fails(C._parseHex, "Z")
         fails(C._parseHex, "A")
         fails(C._parseDate, "2000/1/1")
+        fails(C._parseDate, "2000/10-10")
+        fails(C._parseDate, "2000-10/10")
         fails(C._parseDate, "2000/50/01")
         fails(C._parseDate, "2000/50/01 12:12:12")
-        fails(C._parseTime, "2000/50/01 12:12:12")
+        fails(C._parseTime, "2000/50-01 12:12:12")
+        fails(C._parseDate, "2000-50/01 12:12:12")
+        fails(C._parseDate, "2000-50-01 12:12:12.3")
         fails(C._parseTime, "2000/50/01 12:12:99")
         fails(C._parseNickname, "Mrs Premise")
         fails(C._parseNickname, "../../../AllYourBase")

Index: Config.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/Config.py,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -d -r1.47 -r1.48
--- Config.py	5 Jun 2003 18:41:40 -0000	1.47
+++ Config.py	21 Jun 2003 21:47:50 -0000	1.48
@@ -287,37 +287,57 @@
         raise ConfigError("Invalid exponent on public key")
     return key
 
-# Regular expression to match YYYY/MM/DD
-_date_re = re.compile(r"^(\d\d\d\d)/(\d\d)/(\d\d)$")
+# FFFF006 begin generating YYYY-MM-DD
+# FFFF007 stop accepting YYYYY/MM/DD
+# Regular expression to match YYYY/MM/DD or YYYY-MM-DD
+_date_re = re.compile(r"^(\d\d\d\d)([/-])(\d\d)([/-])(\d\d)$")
 def _parseDate(s):
-    """Validation function.  Converts from YYYY/MM/DD format to a (long)
-       time value for midnight on that date."""
+    """Validation function.  Converts from YYYY-MM-DD or YYYY/MM/DD
+       format to a (long) time value for midnight on that date."""
     m = _date_re.match(s.strip())
+    if not m or m.group(2) != m.group(4):
+        raise ConfigError("Invalid date %r"%s)
     try:
-        yyyy, MM, dd = map(int, m.groups())
+        yyyy = int(m.group(1))
+        MM = int(m.group(3))
+        dd = int(m.group(5))
     except (ValueError,AttributeError):
         raise ConfigError("Invalid date %r"%s)
     if not ((1 <= dd <= 31) and (1 <= MM <= 12) and
             (1970 <= yyyy)):
-        raise ConfigError("Invalid date %s"%s)
+        raise ConfigError("Invalid date %r"%s)
     return calendar.timegm((yyyy,MM,dd,0,0,0,0,0,0))
 
+
+# FFFF006 begin generating YYYY-MM-DD
+# FFFF007 stop accepting YYYYY/MM/DD
 # Regular expression to match YYYY/MM/DD HH:MM:SS
-_time_re = re.compile(r"^(\d\d\d\d)/(\d\d)/(\d\d) (\d\d):(\d\d):(\d\d)$")
+_time_re = re.compile(r"^(\d\d\d\d)([/-])(\d\d)([/-])(\d\d)\s+"
+                      r"(\d\d):(\d\d):(\d\d)((?:\.\d\d\d)?)$")
 def _parseTime(s):
     """Validation function.  Converts from YYYY/MM/DD HH:MM:SS format
        to a (float) time value for GMT."""
     m = _time_re.match(s.strip())
-    if not m:
+    if not m or m.group(2) != m.group(4):
         raise ConfigError("Invalid time %r" % s)
 
-    yyyy, MM, dd, hh, mm, ss = map(int, m.groups())
+    yyyy = int(m.group(1))
+    MM = int(m.group(3))
+    dd = int(m.group(5))
+    hh = int(m.group(6))
+    mm = int(m.group(7))
+    ss = int(m.group(8))
+    if m.group(9):
+        fsec = float(m.group(9))
+    else:
+        fsec = 0.0
+
     if not ((1 <= dd <= 31) and (1 <= MM <= 12) and
             (1970 <= yyyy)  and (0 <= hh < 24) and
             (0 <= mm < 60)  and (0 <= ss <= 61)):
         raise ConfigError("Invalid time %r" % s)
 
-    return calendar.timegm((yyyy,MM,dd,hh,mm,ss,0,0,0))
+    return calendar.timegm((yyyy,MM,dd,hh,mm,ss,0,0,0))+fsec
 
 _NICKNAME_CHARS = ("ABCDEFGHIJKLMNOPQRSTUVWXYZ"+
                    "abcdefghijklmnopqrstuvwxyz"+