Fixed date handling with invalid strings
svn: r1582
This commit is contained in:
parent
f5dbea2a49
commit
e259320e13
@ -30,6 +30,7 @@ __version__ = "$Revision$"
|
|||||||
|
|
||||||
from intl import gettext as _
|
from intl import gettext as _
|
||||||
import re
|
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)
|
fmt7 = re.compile(_start+r"([?\d]+)\s*[./-]\s*([?\d]+)\s*$", re.IGNORECASE)
|
||||||
fmt4 = re.compile(_start+"(\S+)\s+(\d+)\s*$", re.IGNORECASE)
|
fmt4 = re.compile(_start+"(\S+)\s+(\d+)\s*$", re.IGNORECASE)
|
||||||
fmt5 = re.compile(_start+"(\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()
|
matches = match.groups()
|
||||||
mode = self.set_mode_value(matches[0])
|
mode = self.set_mode_value(matches[0])
|
||||||
month = self.set_month_string(matches[2])
|
month = self.set_month_string(matches[2])
|
||||||
|
if month != UNDEF:
|
||||||
day = self.set_value(matches[1])
|
day = self.set_value(matches[1])
|
||||||
if len(matches) == 4 and matches[3] != None:
|
if len(matches) == 4 and matches[3] != None:
|
||||||
year = self.set_value(matches[3])
|
year = self.set_value(matches[3])
|
||||||
@ -487,6 +488,7 @@ class Calendar:
|
|||||||
matches = match.groups()
|
matches = match.groups()
|
||||||
mode = self.set_mode_value(matches[0])
|
mode = self.set_mode_value(matches[0])
|
||||||
month = self.set_month_string(unicode(matches[1]))
|
month = self.set_month_string(unicode(matches[1]))
|
||||||
|
if month != UNDEF:
|
||||||
if matches[2]:
|
if matches[2]:
|
||||||
val = matches[2].replace(',','')
|
val = matches[2].replace(',','')
|
||||||
day = self.set_value(val)
|
day = self.set_value(val)
|
||||||
@ -498,17 +500,12 @@ class Calendar:
|
|||||||
matches = match.groups()
|
matches = match.groups()
|
||||||
mode = self.set_mode_value(matches[0])
|
mode = self.set_mode_value(matches[0])
|
||||||
month = self.set_month_string(unicode(matches[1]))
|
month = self.set_month_string(unicode(matches[1]))
|
||||||
|
if month != UNDEF:
|
||||||
if len(matches) == 4:
|
if len(matches) == 4:
|
||||||
year = self.set_value(matches[3])
|
year = self.set_value(matches[3])
|
||||||
return (year,month,day,mode)
|
return (year,month,day,mode)
|
||||||
|
|
||||||
match = fmt6.match(text)
|
raise Errors.DateError
|
||||||
if match != None:
|
|
||||||
matches = match.groups()
|
|
||||||
mode = self.set_mode_value(matches[0])
|
|
||||||
month = self.set_value(matches[1])
|
|
||||||
|
|
||||||
return (year,month,day,mode)
|
|
||||||
|
|
||||||
|
|
||||||
_FMT_FUNC = [
|
_FMT_FUNC = [
|
||||||
@ -550,5 +547,3 @@ def calendar_names():
|
|||||||
list.append(n)
|
list.append(n)
|
||||||
list.sort()
|
list.sort()
|
||||||
return list
|
return list
|
||||||
|
|
||||||
|
|
||||||
|
@ -42,6 +42,7 @@ import Gregorian
|
|||||||
import Julian
|
import Julian
|
||||||
import Hebrew
|
import Hebrew
|
||||||
import FrenchRepublic
|
import FrenchRepublic
|
||||||
|
import Errors
|
||||||
|
|
||||||
from intl import gettext as _
|
from intl import gettext as _
|
||||||
|
|
||||||
@ -71,8 +72,6 @@ class Date:
|
|||||||
"""
|
"""
|
||||||
formatCode = 0
|
formatCode = 0
|
||||||
|
|
||||||
Error = "Illegal Date"
|
|
||||||
|
|
||||||
fstr = _("(from|between|bet|bet.)")
|
fstr = _("(from|between|bet|bet.)")
|
||||||
tstr = _("(and|to|-)")
|
tstr = _("(and|to|-)")
|
||||||
|
|
||||||
@ -207,7 +206,7 @@ class Date:
|
|||||||
else:
|
else:
|
||||||
self.start.set(text)
|
self.start.set(text)
|
||||||
self.range = 0
|
self.range = 0
|
||||||
except Date.Error:
|
except Errors.DateError:
|
||||||
if text != "":
|
if text != "":
|
||||||
self.range = -1
|
self.range = -1
|
||||||
self.text = text
|
self.text = text
|
||||||
|
@ -18,6 +18,15 @@
|
|||||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
# 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):
|
class ReportError(Exception):
|
||||||
"""Error used to report Report errors"""
|
"""Error used to report Report errors"""
|
||||||
def __init__(self,value,value2=""):
|
def __init__(self,value,value2=""):
|
||||||
|
Loading…
Reference in New Issue
Block a user