Mercurial > p > roundup > code
comparison test/test_dates.py @ 3954:3d5a0a949107
Fix granularity stuff so it handles wrapping a lot better.
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Sun, 23 Dec 2007 00:23:23 +0000 |
| parents | 78dc9b275aeb |
| children | 85cbaa50eba1 |
comparison
equal
deleted
inserted
replaced
| 3953:78dc9b275aeb | 3954:3d5a0a949107 |
|---|---|
| 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.43 2007-12-21 11:21:09 richard Exp $ | 18 # $Id: test_dates.py,v 1.44 2007-12-23 00:23:23 richard Exp $ |
| 19 from __future__ import nested_scopes | 19 from __future__ import nested_scopes |
| 20 | 20 |
| 21 import unittest | 21 import unittest |
| 22 import time | 22 import time |
| 23 import datetime | 23 import datetime |
| 24 import calendar | 24 import calendar |
| 25 | 25 |
| 26 from roundup.date import Date, Interval, Range, fixTimeOverflow, \ | 26 from roundup.date import Date, Interval, Range, fixTimeOverflow, \ |
| 27 get_timezone, _add_granularity | 27 get_timezone |
| 28 | 28 |
| 29 | 29 |
| 30 class DateTestCase(unittest.TestCase): | 30 class DateTestCase(unittest.TestCase): |
| 31 def testAddGranularity(self): | |
| 32 def d(m=None, d=None, H=None, M=None, S=None, value=1): | |
| 33 d = dict(y='2006', m=m, d=d, H=H, M=M, S=S) | |
| 34 _add_granularity(d, 'SMHdmy', value) | |
| 35 return d | |
| 36 ae = self.assertEqual | |
| 37 ae(d(), dict(y=2007, m=None, d=None, H=None, M=None, S=None)) | |
| 38 ae(d(m='1'), dict(y='2006', m=2, d=None, H=None, M=None, S=None)) | |
| 39 ae(d(m='12'), dict(y=2007, m=1, d=None, H=None, M=None, S=None)) | |
| 40 | 31 |
| 41 def testDateInterval(self): | 32 def testDateInterval(self): |
| 42 ae = self.assertEqual | 33 ae = self.assertEqual |
| 43 date = Date("2000-06-26.00:34:02 + 2d") | 34 date = Date("2000-06-26.00:34:02 + 2d") |
| 44 ae(str(date), '2000-06-28.00:34:02') | 35 ae(str(date), '2000-06-28.00:34:02') |
| 369 ae = self.assertEqual | 360 ae = self.assertEqual |
| 370 ae(str(Date('2003-2-12', add_granularity=1)), '2003-02-12.23:59:59') | 361 ae(str(Date('2003-2-12', add_granularity=1)), '2003-02-12.23:59:59') |
| 371 ae(str(Date('2003-1-1.23:00', add_granularity=1)), '2003-01-01.23:00:59') | 362 ae(str(Date('2003-1-1.23:00', add_granularity=1)), '2003-01-01.23:00:59') |
| 372 ae(str(Date('2003', add_granularity=1)), '2003-12-31.23:59:59') | 363 ae(str(Date('2003', add_granularity=1)), '2003-12-31.23:59:59') |
| 373 ae(str(Date('2003-5', add_granularity=1)), '2003-05-31.23:59:59') | 364 ae(str(Date('2003-5', add_granularity=1)), '2003-05-31.23:59:59') |
| 365 ae(str(Date('2003-12', add_granularity=1)), '2003-12-31.23:59:59') | |
| 374 ae(str(Interval('+1w', add_granularity=1)), '+ 14d') | 366 ae(str(Interval('+1w', add_granularity=1)), '+ 14d') |
| 375 ae(str(Interval('-2m 3w', add_granularity=1)), '- 2m 14d') | 367 ae(str(Interval('-2m 3w', add_granularity=1)), '- 2m 14d') |
| 376 | 368 |
| 377 def testIntervalPretty(self): | 369 def testIntervalPretty(self): |
| 378 def ae(spec, pretty): | 370 def ae(spec, pretty): |
| 477 ae(str(date), '2006-04-04.10:00:00') | 469 ae(str(date), '2006-04-04.10:00:00') |
| 478 date = Date('2006-01-01.12:00:00') | 470 date = Date('2006-01-01.12:00:00') |
| 479 date = Date(date, tz) | 471 date = Date(date, tz) |
| 480 ae(str(date), '2006-01-01.11:00:00') | 472 ae(str(date), '2006-01-01.11:00:00') |
| 481 | 473 |
| 474 | |
| 482 class RangeTestCase(unittest.TestCase): | 475 class RangeTestCase(unittest.TestCase): |
| 476 | |
| 483 def testRange(self): | 477 def testRange(self): |
| 484 ae = self.assertEqual | 478 ae = self.assertEqual |
| 485 r = Range('2006', Date) | 479 r = Range('2006', Date) |
| 486 ae(str(r.from_value), '2006-01-01.00:00:00') | 480 ae(str(r.from_value), '2006-01-01.00:00:00') |
| 487 ae(str(r.to_value), '2006-12-31.23:59:59') | 481 ae(str(r.to_value), '2006-12-31.23:59:59') |
