|
15 | 15 | # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, |
16 | 16 | # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
17 | 17 | # |
18 | | -# $Id: date.py,v 1.21 2002-05-15 06:32:46 richard Exp $ |
| 18 | +# $Id: date.py,v 1.22 2002-07-14 06:05:50 richard Exp $ |
19 | 19 |
|
20 | 20 | __doc__ = """ |
21 | 21 | Date, time and time interval handling. |
@@ -91,29 +91,17 @@ def __init__(self, spec='.', offset=0): |
91 | 91 | self.year, self.month, self.day, self.hour, self.minute, \ |
92 | 92 | self.second, x, x, x = time.gmtime(ts) |
93 | 93 |
|
94 | | - def applyInterval(self, interval): |
95 | | - ''' Apply the interval to this date |
| 94 | + def addInterval(self, interval): |
| 95 | + ''' Add the interval to this date, returning the date tuple |
96 | 96 | ''' |
97 | | - t = (self.year + interval.year, |
98 | | - self.month + interval.month, |
99 | | - self.day + interval.day, |
100 | | - self.hour + interval.hour, |
101 | | - self.minute + interval.minute, |
102 | | - self.second + interval.second, 0, 0, 0) |
103 | | - self.year, self.month, self.day, self.hour, self.minute, \ |
104 | | - self.second, x, x, x = time.gmtime(calendar.timegm(t)) |
105 | | - |
106 | | - def __add__(self, other): |
107 | | - """Add an interval to this date to produce another date. |
108 | | - """ |
109 | 97 | # do the basic calc |
110 | | - sign = other.sign |
111 | | - year = self.year + sign * other.year |
112 | | - month = self.month + sign * other.month |
113 | | - day = self.day + sign * other.day |
114 | | - hour = self.hour + sign * other.hour |
115 | | - minute = self.minute + sign * other.minute |
116 | | - second = self.second + sign * other.second |
| 98 | + sign = interval.sign |
| 99 | + year = self.year + sign * interval.year |
| 100 | + month = self.month + sign * interval.month |
| 101 | + day = self.day + sign * interval.day |
| 102 | + hour = self.hour + sign * interval.hour |
| 103 | + minute = self.minute + sign * interval.minute |
| 104 | + second = self.second + sign * interval.second |
117 | 105 |
|
118 | 106 | # now cope with under- and over-flow |
119 | 107 | # first do the time |
@@ -148,8 +136,18 @@ def __add__(self, other): |
148 | 136 | # re-figure the number of days for this month |
149 | 137 | if month == 2 and calendar.isleap(year): month_days = 29 |
150 | 138 | else: month_days = mdays[month] |
| 139 | + return (year, month, day, hour, minute, second, 0, 0, 0) |
151 | 140 |
|
152 | | - return Date((year, month, day, hour, minute, second, 0, 0, 0)) |
| 141 | + def applyInterval(self, interval): |
| 142 | + ''' Apply the interval to this date |
| 143 | + ''' |
| 144 | + self.year, self.month, self.day, self.hour, self.minute, \ |
| 145 | + self.second, x, x, x = self.addInterval(interval) |
| 146 | + |
| 147 | + def __add__(self, interval): |
| 148 | + """Add an interval to this date to produce another date. |
| 149 | + """ |
| 150 | + return Date(self.addInterval(interval)) |
153 | 151 |
|
154 | 152 | # XXX deviates from spec to allow subtraction of dates as well |
155 | 153 | def __sub__(self, other): |
@@ -440,6 +438,9 @@ def test(): |
440 | 438 |
|
441 | 439 | # |
442 | 440 | # $Log: not supported by cvs2svn $ |
| 441 | +# Revision 1.21 2002/05/15 06:32:46 richard |
| 442 | +# . reverting to dates for intervals > 2 months sucks |
| 443 | +# |
443 | 444 | # Revision 1.20 2002/02/21 23:34:51 richard |
444 | 445 | # Oops, there's 24 hours in a day, and subtraction of intervals now works |
445 | 446 | # properly. |
|
0 commit comments