From 465e9508888aa3145c0bf9a5d15b9b38c7fddb2f Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Sat, 19 Apr 2008 04:51:12 +0000 Subject: [PATCH] further fixes for slash dates and updates to unit tests svn: r10588 --- src/DateHandler/_DateParser.py | 8 ++++---- src/gen/lib/date.py | 10 ++++++---- src/gen/lib/test/date_test.py | 20 +++++++------------- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/src/DateHandler/_DateParser.py b/src/DateHandler/_DateParser.py index 0b16159ec..32e03395e 100644 --- a/src/DateHandler/_DateParser.py +++ b/src/DateHandler/_DateParser.py @@ -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) diff --git a/src/gen/lib/date.py b/src/gen/lib/date.py index 9502166ef..6e7f6238d 100644 --- a/src/gen/lib/date.py +++ b/src/gen/lib/date.py @@ -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() diff --git a/src/gen/lib/test/date_test.py b/src/gen/lib/test/date_test.py index ed9513825..4d41353e5 100644 --- a/src/gen/lib/test/date_test.py +++ b/src/gen/lib/test/date_test.py @@ -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