From a1561563943cc09955d6aaea00196765b04e525c Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Sun, 28 Dec 2008 05:44:01 +0000 Subject: [PATCH] Fixed a bug in negative date differences; enhanced Span repr (shows days, if short enough) svn: r11532 --- src/gen/lib/date.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/gen/lib/date.py b/src/gen/lib/date.py index 564a0ef4b..ce6a8c9c0 100644 --- a/src/gen/lib/date.py +++ b/src/gen/lib/date.py @@ -78,11 +78,19 @@ class Span: return self.diff_tuple[pos] def __repr__(self): + retval = "" + if self.diff_tuple[0] != 0: + retval += (_("%d years") % self.diff_tuple[0]) if self.diff_tuple[1] != 0: - retval = ((_("%d years") % self.diff_tuple[0])+ ", " + - (_("%d months") % self.diff_tuple[1])) - else: - retval = (_("%d years") % self.diff_tuple[0]) + if retval != "": + retval += ", " + retval += (_("%d months") % self.diff_tuple[1]) + if self.diff_tuple[2] != 0 and "," not in retval: + if retval != "": + retval += ", " + retval += (_("%d days") % self.diff_tuple[2]) + if retval == "": + retval = "0 days" return retval def __int__(self): @@ -354,9 +362,9 @@ class Date: if date1.calendar != date2.calendar: diff = date1.sortval - date2.sortval if negative: - return Span(diff/365, (diff % 365)/30, (diff % 365) % 30) - else: return Span(-diff/365, -((diff % 365)/30), -((diff % 365) % 30)) + else: + return Span(diff/365, (diff % 365)/30, (diff % 365) % 30) # days: if d2[2] > d1[2]: # months: