Mercurial > p > roundup > code
comparison test/test_dates.py @ 3822:2a60b68985db
Fix arbitrary limit on dates.
Dates can now be in the year-range 1-9999 for all backends except
metakit which is still limited to 1970-2038.
| author | Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net> |
|---|---|
| date | Fri, 09 Mar 2007 10:25:10 +0000 |
| parents | a9126b8033c5 |
| children | a5fb7698439d |
comparison
equal
deleted
inserted
replaced
| 3821:5ed4c9d30148 | 3822:2a60b68985db |
|---|---|
| 13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | 13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" | 14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" |
| 15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, | 15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, |
| 16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | 16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 17 # | 17 # |
| 18 # $Id: test_dates.py,v 1.39 2006-05-06 17:21:34 a1s Exp $ | 18 # $Id: test_dates.py,v 1.40 2007-03-09 10:25:10 schlatterbeck Exp $ |
| 19 from __future__ import nested_scopes | 19 from __future__ import nested_scopes |
| 20 | 20 |
| 21 import unittest, time | 21 import unittest, time |
| 22 | 22 |
| 23 from roundup.date import Date, Interval, Range, fixTimeOverflow, get_timezone | 23 from roundup.date import Date, Interval, Range, fixTimeOverflow, get_timezone |
| 57 ae(str(date), '%s-%02d-%02d.14:25:00'%(y, m, d)) | 57 ae(str(date), '%s-%02d-%02d.14:25:00'%(y, m, d)) |
| 58 date = Date("8:47:11") | 58 date = Date("8:47:11") |
| 59 ae(str(date), '%s-%02d-%02d.08:47:11'%(y, m, d)) | 59 ae(str(date), '%s-%02d-%02d.08:47:11'%(y, m, d)) |
| 60 ae(str(Date('2003')), '2003-01-01.00:00:00') | 60 ae(str(Date('2003')), '2003-01-01.00:00:00') |
| 61 ae(str(Date('2004-06')), '2004-06-01.00:00:00') | 61 ae(str(Date('2004-06')), '2004-06-01.00:00:00') |
| 62 ae(str(Date('1900-02-01')), '1900-02-01.00:00:00') | |
| 63 ae(str(Date('1800-07-15')), '1800-07-15.00:00:00') | |
| 62 | 64 |
| 63 def testDateError(self): | 65 def testDateError(self): |
| 64 self.assertRaises(ValueError, Date, "12") | 66 self.assertRaises(ValueError, Date, "12") |
| 65 # Date cannot handle dates before UNIX epoch | 67 # Date cannot handle dates before year 1 |
| 66 self.assertRaises(ValueError, Date, (1, 1, 1, 0, 0, 0.0, 0, 1, -1)) | 68 self.assertRaises(ValueError, Date, (0, 1, 1, 0, 0, 0.0, 0, 1, -1)) |
| 67 self.assertRaises(ValueError, Date, "1/1/06") | 69 self.assertRaises(ValueError, Date, "1/1/06") |
| 68 | 70 |
| 69 def testOffset(self): | 71 def testOffset(self): |
| 70 ae = self.assertEqual | 72 ae = self.assertEqual |
| 71 date = Date("2000-04-17", -5) | 73 date = Date("2000-04-17", -5) |
| 126 | 128 |
| 127 date = Date('2000-02-28.22:58:59') + Interval('00:00:3661') | 129 date = Date('2000-02-28.22:58:59') + Interval('00:00:3661') |
| 128 ae(str(date), '2000-02-29.00:00:00') | 130 ae(str(date), '2000-02-29.00:00:00') |
| 129 date = Date('2001-02-28.22:58:59') + Interval('00:00:3661') | 131 date = Date('2001-02-28.22:58:59') + Interval('00:00:3661') |
| 130 ae(str(date), '2001-03-01.00:00:00') | 132 ae(str(date), '2001-03-01.00:00:00') |
| 133 date = Date('2001-03-01.00:00:00') + Interval('150y') | |
| 134 ae(str(date), '2151-03-01.00:00:00') | |
| 131 | 135 |
| 132 def testOffsetSub(self): | 136 def testOffsetSub(self): |
| 133 ae = self.assertEqual | 137 ae = self.assertEqual |
| 134 date = Date('2000-12-01') - Interval('- 1d') | 138 date = Date('2000-12-01') - Interval('- 1d') |
| 135 | 139 |
| 160 | 164 |
| 161 date = Date('2000-02-29.00:00:00') - Interval('00:00:3661') | 165 date = Date('2000-02-29.00:00:00') - Interval('00:00:3661') |
| 162 ae(str(date), '2000-02-28.22:58:59') | 166 ae(str(date), '2000-02-28.22:58:59') |
| 163 date = Date('2001-03-01.00:00:00') - Interval('00:00:3661') | 167 date = Date('2001-03-01.00:00:00') - Interval('00:00:3661') |
| 164 ae(str(date), '2001-02-28.22:58:59') | 168 ae(str(date), '2001-02-28.22:58:59') |
| 169 date = Date('2001-03-01.00:00:00') - Interval('150y') | |
| 170 ae(str(date), '1851-03-01.00:00:00') | |
| 165 | 171 |
| 166 def testDateLocal(self): | 172 def testDateLocal(self): |
| 167 ae = self.assertEqual | 173 ae = self.assertEqual |
| 168 date = Date("02:42:20") | 174 date = Date("02:42:20") |
| 169 date = date.local(10) | 175 date = date.local(10) |
| 267 i = Date('2003-03-01.00:00:00') - Date('2003-02-01.00:00:00') | 273 i = Date('2003-03-01.00:00:00') - Date('2003-02-01.00:00:00') |
| 268 self.assertEqual(i, Interval('28d')) | 274 self.assertEqual(i, Interval('28d')) |
| 269 # force the transition over a year boundary | 275 # force the transition over a year boundary |
| 270 i = Date('2003-01-01.00:00:00') - Date('2002-01-01.00:00:00') | 276 i = Date('2003-01-01.00:00:00') - Date('2002-01-01.00:00:00') |
| 271 self.assertEqual(i, Interval('365d')) | 277 self.assertEqual(i, Interval('365d')) |
| 278 i = Date('1952-01-01') - Date('1953-01-01') | |
| 279 self.assertEqual(i, Interval('-366d')) | |
| 280 i = Date('1953-01-01') - Date('1952-01-01') | |
| 281 self.assertEqual(i, Interval('366d')) | |
| 272 | 282 |
| 273 def testIntervalAdd(self): | 283 def testIntervalAdd(self): |
| 274 ae = self.assertEqual | 284 ae = self.assertEqual |
| 275 ae(str(Interval('1y') + Interval('1y')), '+ 2y') | 285 ae(str(Interval('1y') + Interval('1y')), '+ 2y') |
| 276 ae(str(Interval('1y') + Interval('1m')), '+ 1y 1m') | 286 ae(str(Interval('1y') + Interval('1m')), '+ 1y 1m') |
| 387 import datetime | 397 import datetime |
| 388 except: | 398 except: |
| 389 return | 399 return |
| 390 d = datetime.datetime.now() | 400 d = datetime.datetime.now() |
| 391 Date(d) | 401 Date(d) |
| 402 toomuch = datetime.MAXYEAR + 1 | |
| 403 self.assertRaises(ValueError, Date, (toomuch, 1, 1, 0, 0, 0, 0, 1, -1)) | |
| 392 | 404 |
| 393 def testSimpleTZ(self): | 405 def testSimpleTZ(self): |
| 394 ae = self.assertEqual | 406 ae = self.assertEqual |
| 395 # local to utc | 407 # local to utc |
| 396 date = Date('2006-04-04.12:00:00', 2) | 408 date = Date('2006-04-04.12:00:00', 2) |
| 402 # from Date instance | 414 # from Date instance |
| 403 date = Date('2006-04-04.12:00:00') | 415 date = Date('2006-04-04.12:00:00') |
| 404 date = Date(date, 2) | 416 date = Date(date, 2) |
| 405 ae(str(date), '2006-04-04.10:00:00') | 417 ae(str(date), '2006-04-04.10:00:00') |
| 406 | 418 |
| 419 def testTimestamp(self): | |
| 420 ae = self.assertEqual | |
| 421 date = Date('2038') | |
| 422 ae(date.timestamp(), 2145916800) | |
| 423 date = Date('1902') | |
| 424 ae(date.timestamp(), -2145916800) | |
| 425 try: | |
| 426 from time import gmtime | |
| 427 except: | |
| 428 return | |
| 429 date = Date(gmtime(0)) | |
| 430 ae(date.timestamp(), 0) | |
| 431 ae(str(date), '1970-01-01.00:00:00') | |
| 432 date = Date(gmtime(0x7FFFFFFF)) | |
| 433 ae(date.timestamp(), 2147483647) | |
| 434 ae(str(date), '2038-01-19.03:14:07') | |
| 435 date = Date('1901-12-13.20:45:52') | |
| 436 ae(date.timestamp(), -0x80000000L) | |
| 437 ae(str(date), '1901-12-13.20:45:52') | |
| 438 date = Date('9999') | |
| 439 ae (date.timestamp(), 253370764800.0) | |
| 440 date = Date('0033') | |
| 441 ae (date.timestamp(), -61125753600.0) | |
| 442 ae(str(date), '0033-01-01.00:00:00') | |
| 443 | |
| 407 class TimezoneTestCase(unittest.TestCase): | 444 class TimezoneTestCase(unittest.TestCase): |
| 408 | 445 |
| 409 def testTZ(self): | 446 def testTZ(self): |
| 410 ae = self.assertEqual | 447 ae = self.assertEqual |
| 411 tz = 'Europe/Warsaw' | 448 tz = 'Europe/Warsaw' |
