Fixed date handling with invalid strings

svn: r1582
This commit is contained in:
Don Allingham 2003-05-23 02:45:44 +00:00
parent f5dbea2a49
commit e259320e13
3 changed files with 28 additions and 25 deletions

View File

@ -30,6 +30,7 @@ __version__ = "$Revision$"
from intl import gettext as _
import re
import Errors
#-------------------------------------------------------------------------
#
@ -66,7 +67,6 @@ fmt3 = re.compile(_start+r"([?\d]+)\s*[./-]\s*([?\d]+)\s*[./-]\s*([?\d]+)\s*$",
fmt7 = re.compile(_start+r"([?\d]+)\s*[./-]\s*([?\d]+)\s*$", re.IGNORECASE)
fmt4 = re.compile(_start+"(\S+)\s+(\d+)\s*$", re.IGNORECASE)
fmt5 = re.compile(_start+"(\d+)\s*$", re.IGNORECASE)
fmt6 = re.compile(_start+"(\S+)\s*$", re.IGNORECASE)
#-------------------------------------------------------------------------
@ -440,6 +440,7 @@ class Calendar:
matches = match.groups()
mode = self.set_mode_value(matches[0])
month = self.set_month_string(matches[2])
if month != UNDEF:
day = self.set_value(matches[1])
if len(matches) == 4 and matches[3] != None:
year = self.set_value(matches[3])
@ -487,6 +488,7 @@ class Calendar:
matches = match.groups()
mode = self.set_mode_value(matches[0])
month = self.set_month_string(unicode(matches[1]))
if month != UNDEF:
if matches[2]:
val = matches[2].replace(',','')
day = self.set_value(val)
@ -498,17 +500,12 @@ class Calendar:
matches = match.groups()
mode = self.set_mode_value(matches[0])
month = self.set_month_string(unicode(matches[1]))
if month != UNDEF:
if len(matches) == 4:
year = self.set_value(matches[3])
return (year,month,day,mode)
match = fmt6.match(text)
if match != None:
matches = match.groups()
mode = self.set_mode_value(matches[0])
month = self.set_value(matches[1])
return (year,month,day,mode)
raise Errors.DateError
_FMT_FUNC = [
@ -550,5 +547,3 @@ def calendar_names():
list.append(n)
list.sort()
return list

View File

@ -42,6 +42,7 @@ import Gregorian
import Julian
import Hebrew
import FrenchRepublic
import Errors
from intl import gettext as _
@ -71,8 +72,6 @@ class Date:
"""
formatCode = 0
Error = "Illegal Date"
fstr = _("(from|between|bet|bet.)")
tstr = _("(and|to|-)")
@ -207,7 +206,7 @@ class Date:
else:
self.start.set(text)
self.range = 0
except Date.Error:
except Errors.DateError:
if text != "":
self.range = -1
self.text = text

View File

@ -18,6 +18,15 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
class DateError(Exception):
"""Error used to report Date errors"""
def __init__(self,value=""):
Exception.__init__(self)
self.value = value
def __str__(self):
return self.value
class ReportError(Exception):
"""Error used to report Report errors"""
def __init__(self,value,value2=""):