Date spans that are negative show with negative year, month, and day
svn: r11521
This commit is contained in:
parent
b206ca7cda
commit
a11d819296
@ -331,13 +331,18 @@ class Date:
|
|||||||
|
|
||||||
date1 = self
|
date1 = self
|
||||||
date2 = other
|
date2 = other
|
||||||
|
negative = False
|
||||||
if d1 < d2:
|
if d1 < d2:
|
||||||
d1, d2 = d2, d1
|
d1, d2 = d2, d1
|
||||||
date1, date2 = date2, date1
|
date1, date2 = date2, date1
|
||||||
|
negative = True
|
||||||
# d1 - d2 (1998, 12, 32) - (1982, 12, 15)
|
# d1 - d2 (1998, 12, 32) - (1982, 12, 15)
|
||||||
if date1.calendar != date2.calendar:
|
if date1.calendar != date2.calendar:
|
||||||
diff = date1.sortval - date2.sortval
|
diff = date1.sortval - date2.sortval
|
||||||
|
if negative:
|
||||||
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:
|
||||||
@ -369,6 +374,9 @@ class Date:
|
|||||||
eDate = eDate + (0, 0, diff)
|
eDate = eDate + (0, 0, diff)
|
||||||
if diff == 60:
|
if diff == 60:
|
||||||
return Span(-1, -1, -1)
|
return Span(-1, -1, -1)
|
||||||
|
if negative:
|
||||||
|
return Span(-years, -months, -(days - diff))
|
||||||
|
else:
|
||||||
return Span(years, months, days - diff)
|
return Span(years, months, days - diff)
|
||||||
elif eDate > date2:
|
elif eDate > date2:
|
||||||
diff = 0
|
diff = 0
|
||||||
@ -377,7 +385,13 @@ class Date:
|
|||||||
eDate = eDate - (0, 0, abs(diff))
|
eDate = eDate - (0, 0, abs(diff))
|
||||||
if diff == -60:
|
if diff == -60:
|
||||||
return Span(-1, -1, -1)
|
return Span(-1, -1, -1)
|
||||||
|
if negative:
|
||||||
|
return Span(-years, -months, -(days + diff))
|
||||||
|
else:
|
||||||
return Span(years, months, days + diff)
|
return Span(years, months, days + diff)
|
||||||
|
else:
|
||||||
|
if negative:
|
||||||
|
return Span(-years, -months, -days)
|
||||||
else:
|
else:
|
||||||
return Span(years, months, days)
|
return Span(years, months, days)
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user