|
15 | 15 | # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, |
16 | 16 | # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
17 | 17 | # |
18 | | -# $Id: test_dates.py,v 1.25 2003-10-25 22:53:26 richard Exp $ |
| 18 | +# $Id: test_dates.py,v 1.26 2003-11-02 09:27:50 richard Exp $ |
19 | 19 |
|
20 | 20 | import unittest, time |
21 | 21 |
|
@@ -177,6 +177,71 @@ def testIntervalInitDate(self): |
177 | 177 | then = now - Interval('2d') |
178 | 178 | ae(str(Interval(str(then))), '- 2d') |
179 | 179 |
|
| 180 | + def testIntervalAddMonthBoundary(self): |
| 181 | + # force the transition over a month boundary |
| 182 | + now = Date('2003-10-30.00:00:00') |
| 183 | + then = now + Interval('2d') |
| 184 | + self.assertEqual(str(then), '2003-11-01.00:00:00') |
| 185 | + now = Date('2004-02-28.00:00:00') |
| 186 | + then = now + Interval('1d') |
| 187 | + self.assertEqual(str(then), '2004-02-29.00:00:00') |
| 188 | + now = Date('2003-02-28.00:00:00') |
| 189 | + then = now + Interval('1d') |
| 190 | + self.assertEqual(str(then), '2003-03-01.00:00:00') |
| 191 | + now = Date('2003-01-01.00:00:00') |
| 192 | + then = now + Interval('59d') |
| 193 | + self.assertEqual(str(then), '2003-03-01.00:00:00') |
| 194 | + now = Date('2004-01-01.00:00:00') |
| 195 | + then = now + Interval('59d') |
| 196 | + self.assertEqual(str(then), '2004-02-29.00:00:00') |
| 197 | + |
| 198 | + def testIntervalSubtractMonthBoundary(self): |
| 199 | + # force the transition over a month boundary |
| 200 | + now = Date('2003-11-01.00:00:00') |
| 201 | + then = now - Interval('2d') |
| 202 | + self.assertEqual(str(then), '2003-10-30.00:00:00') |
| 203 | + now = Date('2004-02-29.00:00:00') |
| 204 | + then = now - Interval('1d') |
| 205 | + self.assertEqual(str(then), '2004-02-28.00:00:00') |
| 206 | + now = Date('2003-03-01.00:00:00') |
| 207 | + then = now - Interval('1d') |
| 208 | + self.assertEqual(str(then), '2003-02-08.00:00:00') |
| 209 | + now = Date('2003-03-01.00:00:00') |
| 210 | + then = now - Interval('59d') |
| 211 | + self.assertEqual(str(then), '2003-01-01.00:00:00') |
| 212 | + now = Date('2004-02-29.00:00:00') |
| 213 | + then = now - Interval('59d') |
| 214 | + self.assertEqual(str(then), '2004-01-01.00:00:00') |
| 215 | + |
| 216 | + def testIntervalAddYearBoundary(self): |
| 217 | + # force the transition over a year boundary |
| 218 | + now = Date('2003-12-30.00:00:00') |
| 219 | + then = now + Interval('2d') |
| 220 | + self.assertEqual(str(then), '2004-01-01.00:00:00') |
| 221 | + now = Date('2003-01-01.00:00:00') |
| 222 | + then = now + Interval('364d') |
| 223 | + self.assertEqual(str(then), '2004-01-01.00:00:00') |
| 224 | + now = Date('2004-01-01.00:00:00') |
| 225 | + then = now + Interval('365d') |
| 226 | + self.assertEqual(str(then), '2005-01-01.00:00:00') |
| 227 | + |
| 228 | + def testIntervalSubtractYearBoundary(self): |
| 229 | + # force the transition over a year boundary |
| 230 | + now = Date('2003-01-01.00:00:00') |
| 231 | + then = now - Interval('2d') |
| 232 | + self.assertEqual(str(then), '2002-12-30.00:00:00') |
| 233 | + now = Date('2004-02-01.00:00:00') |
| 234 | + then = now - Interval('365d') |
| 235 | + self.assertEqual(str(then), '2003-02-01.00:00:00') |
| 236 | + now = Date('2005-02-01.00:00:00') |
| 237 | + then = now - Interval('365d') |
| 238 | + self.assertEqual(str(then), '2004-02-02.00:00:00') |
| 239 | + |
| 240 | + def testDateSubtract(self): |
| 241 | + # force the transition over a year boundary |
| 242 | + i = Date('2003-01-01.00:00:00') - Date('2002-01-01.00:00:00') |
| 243 | + self.assertEqual(str(i).strip(), '1y') |
| 244 | + |
180 | 245 | def testIntervalAdd(self): |
181 | 246 | ae = self.assertEqual |
182 | 247 | ae(str(Interval('1y') + Interval('1y')), '+ 2y') |
|
0 commit comments