Fixed a bug in negative date differences; enhanced Span repr (shows days, if short enough)
svn: r11532
This commit is contained in:
parent
c96bf68ee2
commit
a156156394
@ -78,11 +78,19 @@ class Span:
|
|||||||
return self.diff_tuple[pos]
|
return self.diff_tuple[pos]
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
retval = ""
|
||||||
|
if self.diff_tuple[0] != 0:
|
||||||
|
retval += (_("%d years") % self.diff_tuple[0])
|
||||||
if self.diff_tuple[1] != 0:
|
if self.diff_tuple[1] != 0:
|
||||||
retval = ((_("%d years") % self.diff_tuple[0])+ ", " +
|
if retval != "":
|
||||||
(_("%d months") % self.diff_tuple[1]))
|
retval += ", "
|
||||||
else:
|
retval += (_("%d months") % self.diff_tuple[1])
|
||||||
retval = (_("%d years") % self.diff_tuple[0])
|
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
|
return retval
|
||||||
|
|
||||||
def __int__(self):
|
def __int__(self):
|
||||||
@ -354,9 +362,9 @@ class Date:
|
|||||||
if date1.calendar != date2.calendar:
|
if date1.calendar != date2.calendar:
|
||||||
diff = date1.sortval - date2.sortval
|
diff = date1.sortval - date2.sortval
|
||||||
if negative:
|
if negative:
|
||||||
return Span(diff/365, (diff % 365)/30, (diff % 365) % 30)
|
|
||||||
else:
|
|
||||||
return Span(-diff/365, -((diff % 365)/30), -((diff % 365) % 30))
|
return Span(-diff/365, -((diff % 365)/30), -((diff % 365) % 30))
|
||||||
|
else:
|
||||||
|
return Span(diff/365, (diff % 365)/30, (diff % 365) % 30)
|
||||||
# days:
|
# days:
|
||||||
if d2[2] > d1[2]:
|
if d2[2] > d1[2]:
|
||||||
# months:
|
# months:
|
||||||
|
Loading…
Reference in New Issue
Block a user