comparison test/test_dates.py @ 1537:0e36c9b23aa6

more lenient date input and addition Interval input support [SF#677764]
author Richard Jones <richard@users.sourceforge.net>
date Wed, 19 Mar 2003 05:18:11 +0000
parents 26f29449c494
children 4d55f90d4af1
comparison
equal deleted inserted replaced
1536:3408d091da5b 1537:0e36c9b23aa6
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.21 2003-03-19 03:25:30 richard Exp $ 18 # $Id: test_dates.py,v 1.22 2003-03-19 05:18:11 richard Exp $
19 19
20 import unittest, time 20 import unittest, time
21 21
22 from roundup.date import Date, Interval, Range, fixTimeOverflow 22 from roundup.date import Date, Interval, Range, fixTimeOverflow
23 23
32 ae(str(date), '2001-03-01.00:00:00') 32 ae(str(date), '2001-03-01.00:00:00')
33 33
34 def testDate(self): 34 def testDate(self):
35 ae = self.assertEqual 35 ae = self.assertEqual
36 date = Date("2000-04-17") 36 date = Date("2000-04-17")
37 ae(str(date), '2000-04-17.00:00:00')
38 date = Date("2000/04/17")
37 ae(str(date), '2000-04-17.00:00:00') 39 ae(str(date), '2000-04-17.00:00:00')
38 date = Date("2000-4-7") 40 date = Date("2000-4-7")
39 ae(str(date), '2000-04-07.00:00:00') 41 ae(str(date), '2000-04-07.00:00:00')
40 date = Date("2000-4-17") 42 date = Date("2000-4-17")
41 ae(str(date), '2000-04-17.00:00:00') 43 ae(str(date), '2000-04-17.00:00:00')
42 date = Date("01-25") 44 date = Date("01-25")
43 y, m, d, x, x, x, x, x, x = time.gmtime(time.time()) 45 y, m, d, x, x, x, x, x, x = time.gmtime(time.time())
44 ae(str(date), '%s-01-25.00:00:00'%y) 46 ae(str(date), '%s-01-25.00:00:00'%y)
45 date = Date("2000-04-17.03:45") 47 date = Date("2000-04-17.03:45")
48 ae(str(date), '2000-04-17.03:45:00')
49 date = Date("2000/04/17.03:45")
46 ae(str(date), '2000-04-17.03:45:00') 50 ae(str(date), '2000-04-17.03:45:00')
47 date = Date("08-13.22:13") 51 date = Date("08-13.22:13")
48 ae(str(date), '%s-08-13.22:13:00'%y) 52 ae(str(date), '%s-08-13.22:13:00'%y)
49 date = Date("11-07.09:32:43") 53 date = Date("11-07.09:32:43")
50 ae(str(date), '%s-11-07.09:32:43'%y) 54 ae(str(date), '%s-11-07.09:32:43'%y)
160 ae(str(Interval('-2w 3 d ')), '- 17d') 164 ae(str(Interval('-2w 3 d ')), '- 17d')
161 ae(str(Interval(' - 1 d 2:50 ')), '- 1d 2:50') 165 ae(str(Interval(' - 1 d 2:50 ')), '- 1d 2:50')
162 ae(str(Interval(' 14:00 ')), '+ 14:00') 166 ae(str(Interval(' 14:00 ')), '+ 14:00')
163 ae(str(Interval(' 0:04:33 ')), '+ 0:04:33') 167 ae(str(Interval(' 0:04:33 ')), '+ 0:04:33')
164 168
169 def testIntervalInitDate(self):
170 ae = self.assertEqual
171 now = Date('.')
172 now.hour = now.minute = now.second = 0
173 then = now + Interval('2d')
174 ae(str(Interval(str(then))), '+ 2d')
175 then = now - Interval('2d')
176 ae(str(Interval(str(then))), '- 2d')
177
165 def testIntervalAdd(self): 178 def testIntervalAdd(self):
166 ae = self.assertEqual 179 ae = self.assertEqual
167 ae(str(Interval('1y') + Interval('1y')), '+ 2y') 180 ae(str(Interval('1y') + Interval('1y')), '+ 2y')
168 ae(str(Interval('1y') + Interval('1m')), '+ 1y 1m') 181 ae(str(Interval('1y') + Interval('1m')), '+ 1y 1m')
169 ae(str(Interval('1y') + Interval('2:40')), '+ 1y 2:40') 182 ae(str(Interval('1y') + Interval('2:40')), '+ 1y 2:40')

Roundup Issue Tracker: http://roundup-tracker.org/