further fixes for slash dates and updates to unit tests

svn: r10588
This commit is contained in:
Doug Blank 2008-04-19 04:51:12 +00:00
parent 3373062274
commit 465e950888
3 changed files with 17 additions and 21 deletions

View File

@ -328,8 +328,8 @@ class DateParser:
s = False
else:
d = self._get_int(groups[1])
if groups[4] != None: # slash year digit
y = int(groups[3][:-1] + groups[4])
if groups[4] != None: # slash year "/80"
y = int(groups[3]) + 1 # fullyear + 1
s = True
else: # regular, non-slash date
y = int(groups[3])
@ -354,7 +354,7 @@ class DateParser:
s = False
else:
if groups[4] != None: # slash year digit
y = int(groups[3][:-1] + groups[4])
y = int(groups[3]) + 1 # fullyear + 1
s = True
else:
y = int(groups[3])
@ -517,7 +517,7 @@ class DateParser:
try:
text = match.group(1) + match.group(3)
except:
print "MATCH:", match.groups()
print "ERROR MATCH:", match.groups()
bc = True
return (text, bc)

View File

@ -87,7 +87,9 @@ class Span:
def __int__(self):
return int(self.diff_tuple[0] * 12 + self.diff_tuple[1]) # months
def __eq__(self, other):
return self.diff_tuple == other.diff_tuple
#-------------------------------------------------------------------------
#
@ -511,14 +513,14 @@ class Date:
comparison >> :
Returns True if all parts of other_date > all parts of self
"""
if (self.sortval == 0 or other_date.sortval == 0):
return False
elif (other_date.modifier == Date.MOD_TEXTONLY or
if (other_date.modifier == Date.MOD_TEXTONLY or
self.modifier == Date.MOD_TEXTONLY):
if comparison in ["=", "=="]:
return (self.text.upper().find(other_date.text.upper()) != -1)
else:
return False
if (self.sortval == 0 or other_date.sortval == 0):
return False
# Obtain minimal start and maximal stop in Gregorian calendar
other_start, other_stop = other_date.get_start_stop_range()

View File

@ -49,7 +49,7 @@ import Config
import DateHandler
from DateHandler import parser as _dp
from DateHandler import displayer as _dd
from gen.lib import Date
from gen.lib.date import Date, Span
gettext.textdomain("gramps")
gettext.install("gramps",loc,unicode=1)
@ -228,12 +228,6 @@ class Tester(unittest.TestCase):
"""
if expected2 == None:
expected2 = expected1
pos1 = 1
if expected1 :
pos1 = 0
pos2 = 1
if expected2 :
pos2 = 0
date1 = _dp.parse(d1)
date2 = _dp.parse(d2)
if part == 1:
@ -358,12 +352,12 @@ def suite2():
("Date(2000, 1, 1) - 1", "Date(1999, 1, 1)"),
("Date(2000) - 1", "Date(1999)"),
("Date(2000) + 1", "Date(2001)"),
# Date +/- Date -> tuple
("Date(1876,5,7) - Date(1876,5,1)", "(0, 0, 6)"),
("Date(1876,5,7) - Date(1876,4,30)", "(0, 0, 7)"),
("Date(2000,1,1) - Date(1999,2,1)", "(0, 11, 0)"),
("Date(2000,1,1) - Date(1999,12,1)", "(0, 1, 0)"),
("Date(2007, 12, 23) - Date(1963, 12, 4)", "(44, 0, 19)"),
# Date +/- Date -> Span
("Date(1876,5,7) - Date(1876,5,1)", "Span(0, 0, 6)"),
("Date(1876,5,7) - Date(1876,4,30)", "Span(0, 0, 7)"),
("Date(2000,1,1) - Date(1999,2,1)", "Span(0, 11, 0)"),
("Date(2000,1,1) - Date(1999,12,1)", "Span(0, 1, 0)"),
("Date(2007, 12, 23) - Date(1963, 12, 4)", "Span(44, 0, 19)"),
]
suite = unittest.TestSuite()
count = 1