commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gnue/gnue-common/src GDateTime.py FormatMasks/D...


From: Jason Cater
Subject: gnue/gnue-common/src GDateTime.py FormatMasks/D...
Date: Mon, 16 Jul 2001 20:00:08 -0700

CVSROOT:        /home/cvs
Module name:    gnue
Changes by:     Jason Cater <address@hidden>    01/07/16 20:00:08

Modified files:
        gnue-common/src: GDateTime.py 
        gnue-common/src/FormatMasks: DateMask.py 

Log message:
        misc changes

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/src/GDateTime.py.diff?cvsroot=OldCVS&tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/src/FormatMasks/DateMask.py.diff?cvsroot=OldCVS&tr1=1.3&tr2=1.4&r1=text&r2=text

Patches:
Index: gnue/gnue-common/src/FormatMasks/DateMask.py
diff -u gnue/gnue-common/src/FormatMasks/DateMask.py:1.3 
gnue/gnue-common/src/FormatMasks/DateMask.py:1.4
--- gnue/gnue-common/src/FormatMasks/DateMask.py:1.3    Mon Jul 16 13:24:54 2001
+++ gnue/gnue-common/src/FormatMasks/DateMask.py        Mon Jul 16 20:00:08 2001
@@ -53,7 +53,7 @@
 
 from BaseMask import BaseMask, MaskSection, Literal
 from gnue.common import GDebug
-from gnue.common.GDateTime import GDateTime
+from gnue.common.GDateTime import GDateTime, InvalidDate
 from FormatExceptions import *
 
 # TODO: This is obviously not Internationalized!
@@ -72,11 +72,6 @@
 predefinedDateLiterals = "-./: ,"
 
 
-def isLeapYear(year): 
-  return divmod(year,400)[1] == 0 or \
-      (divmod(year,4)[1] == 0 and divmod(year,100)[1] != 0)
-
-
 class DateLiteral (Literal): 
   def addSelfToDate(self, value, date):
     pass
@@ -169,18 +164,21 @@
   def getFormattedOutput(self): 
     rv = ""
     value = self._buildDate(self.entry, 1)
-
-    for m in self.outputHandlers: 
-      rv = rv + m.getFormattedValue(value)
 
-    return rv
+    try: 
+      for m in self.outputHandlers: 
+        rv = rv + m.getFormattedValue(value)
+
+      return rv
+    except InvalidDate, msg:
+      raise InvalidEntry, msg
 
 
   def getFormattedInput(self, padding=""): 
     rv = ""
     value = self._buildDate(self.entry, 0)
 
-#    self.lastInputPos
+    self.lastInputPos = 
 
     print self.inputMaskLen
 
Index: gnue/gnue-common/src/GDateTime.py
diff -u gnue/gnue-common/src/GDateTime.py:1.2 
gnue/gnue-common/src/GDateTime.py:1.3
--- gnue/gnue-common/src/GDateTime.py:1.2       Mon Jul 16 13:24:54 2001
+++ gnue/gnue-common/src/GDateTime.py   Mon Jul 16 20:00:08 2001
@@ -26,6 +26,14 @@
 # NOTES:
 #
 
+
+def isLeapYear(year): 
+  return divmod(year,400)[1] == 0 or \
+      (divmod(year,4)[1] == 0 and divmod(year,100)[1] != 0)
+
+class InvalidDate(StandardError): 
+  pass
+
 class GDateTime: 
   def __init__(self): 
     self.month = 1
@@ -42,4 +50,19 @@
     y = self.year - a
     m = self.month + 12*a - 2
     return divmod(self.day + y + int(y/4) - int(y/100) + int(y/400) + 
(31*m)/12,7)[1]
+
+
+  def validate(self): 
+    if not (\
+        self.month >= 1 and self.month <= 12 and \
+        self.year >= 0 and \
+        self.day >= 1 and self.day <= ( \
+             (self.month in (1,3,5,7,8,10,12) and 31) or \
+             (self.month == 2 and (28 + isLeapYear(self.year))) \
+             or 30) and \
+        self.hour >= 0 and self.hour <= 23 and \
+        self.minute >= 0 and self.minute <= 59 and \
+        self.second >= 0 and self.second <= 59 ):
+      raise InvalidDate, "Not a valid date"
+
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]