Code

- update with possible tracker issue
[roundup.git] / test / test_dates.py
1 #
2 # Copyright (c) 2001 Bizar Software Pty Ltd (http://www.bizarsoftware.com.au/)
3 # This module is free software, and you may redistribute it and/or modify
4 # under the same terms as Python, so long as this copyright message and
5 # disclaimer are retained in their original form.
6 #
7 # IN NO EVENT SHALL BIZAR SOFTWARE PTY LTD BE LIABLE TO ANY PARTY FOR
8 # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
9 # OUT OF THE USE OF THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE
10 # POSSIBILITY OF SUCH DAMAGE.
11 #
12 # BIZAR SOFTWARE PTY LTD SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
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"
15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
17 #
18 # $Id: test_dates.py,v 1.45 2008-03-07 01:11:55 richard Exp $
19 from __future__ import nested_scopes
21 import unittest
22 import time
23 import datetime
24 import calendar
26 from roundup.date import Date, Interval, Range, fixTimeOverflow, \
27     get_timezone
30 class DateTestCase(unittest.TestCase):
32     def testDateInterval(self):
33         ae = self.assertEqual
34         date = Date("2000-06-26.00:34:02 + 2d")
35         ae(str(date), '2000-06-28.00:34:02')
36         date = Date("2000-02-27 + 2d")
37         ae(str(date), '2000-02-29.00:00:00')
38         date = Date("2001-02-27 + 2d")
39         ae(str(date), '2001-03-01.00:00:00')
40         date = Date("2009", add_granularity=True)
41         self.assertRaises(ValueError, Date, ". +30d", add_granularity=True)
42         
43     def testDate(self):
44         ae = self.assertEqual
45         date = Date("2000-04-17")
46         ae(str(date), '2000-04-17.00:00:00')
47         date = Date("2000/04/17")
48         ae(str(date), '2000-04-17.00:00:00')
49         date = Date("2000-4-7")
50         ae(str(date), '2000-04-07.00:00:00')
51         date = Date("2000-4-17")
52         ae(str(date), '2000-04-17.00:00:00')
53         date = Date("01-25")
54         y, m, d, x, x, x, x, x, x = time.gmtime(time.time())
55         ae(str(date), '%s-01-25.00:00:00'%y)
56         date = Date("2000-04-17.03:45")
57         ae(str(date), '2000-04-17.03:45:00')
58         date = Date("2000/04/17.03:45")
59         ae(str(date), '2000-04-17.03:45:00')
60         date = Date("08-13.22:13")
61         ae(str(date), '%s-08-13.22:13:00'%y)
62         date = Date("11-07.09:32:43")
63         ae(str(date), '%s-11-07.09:32:43'%y)
64         date = Date("14:25")
65         ae(str(date), '%s-%02d-%02d.14:25:00'%(y, m, d))
66         date = Date("8:47:11")
67         ae(str(date), '%s-%02d-%02d.08:47:11'%(y, m, d))
68         ae(str(Date('2003')), '2003-01-01.00:00:00')
69         ae(str(Date('2004-06')), '2004-06-01.00:00:00')
70         ae(str(Date('1900-02-01')), '1900-02-01.00:00:00')
71         ae(str(Date('1800-07-15')), '1800-07-15.00:00:00')
73     def testLeapYear(self):
74         self.assertEquals(str(Date('2008-02-29')), '2008-02-29.00:00:00')
76     def testDateError(self):
77         self.assertRaises(ValueError, Date, "12")
78         # Date cannot handle dates before year 1
79         self.assertRaises(ValueError, Date, (0, 1, 1, 0, 0, 0.0, 0, 1, -1))
80         self.assertRaises(ValueError, Date, "1/1/06")
82     def testOffset(self):
83         ae = self.assertEqual
84         date = Date("2000-04-17", -5)
85         ae(str(date), '2000-04-17.05:00:00')
86         date = Date("01-25", -5)
87         y, m, d, x, x, x, x, x, x = time.gmtime(time.time())
88         ae(str(date), '%s-01-25.05:00:00'%y)
89         date = Date("2000-04-17.03:45", -5)
90         ae(str(date), '2000-04-17.08:45:00')
91         date = Date("08-13.22:13", -5)
92         ae(str(date), '%s-08-14.03:13:00'%y)
93         date = Date("11-07.09:32:43", -5)
94         ae(str(date), '%s-11-07.14:32:43'%y)
95         date = Date("14:25", -5)
96         ae(str(date), '%s-%02d-%02d.19:25:00'%(y, m, d))
97         date = Date("8:47:11", -5)
98         ae(str(date), '%s-%02d-%02d.13:47:11'%(y, m, d))
100         # just make sure we parse these, m'kay?
101         date = Date('-1d')
102         date = Date('-1w')
103         date = Date('-1m')
104         date = Date('-1y')
106     def testOffsetRandom(self):
107         ae = self.assertEqual
108         # XXX unsure of the usefulness of these, they're pretty random
109         date = Date('2000-01-01') + Interval('- 2y 2m')
110         ae(str(date), '1997-11-01.00:00:00')
111         date = Date('2000-01-01 - 2y 2m')
112         ae(str(date), '1997-11-01.00:00:00')
113         date = Date('2000-01-01') + Interval('2m')
114         ae(str(date), '2000-03-01.00:00:00')
115         date = Date('2000-01-01 + 2m')
116         ae(str(date), '2000-03-01.00:00:00')
118         date = Date('2000-01-01') + Interval('60d')
119         ae(str(date), '2000-03-01.00:00:00')
120         date = Date('2001-01-01') + Interval('60d')
121         ae(str(date), '2001-03-02.00:00:00')
123     def testOffsetAdd(self):
124         ae = self.assertEqual
125         date = Date('2000-02-28.23:59:59') + Interval('00:00:01')
126         ae(str(date), '2000-02-29.00:00:00')
127         date = Date('2001-02-28.23:59:59') + Interval('00:00:01')
128         ae(str(date), '2001-03-01.00:00:00')
130         date = Date('2000-02-28.23:58:59') + Interval('00:01:01')
131         ae(str(date), '2000-02-29.00:00:00')
132         date = Date('2001-02-28.23:58:59') + Interval('00:01:01')
133         ae(str(date), '2001-03-01.00:00:00')
135         date = Date('2000-02-28.22:58:59') + Interval('01:01:01')
136         ae(str(date), '2000-02-29.00:00:00')
137         date = Date('2001-02-28.22:58:59') + Interval('01:01:01')
138         ae(str(date), '2001-03-01.00:00:00')
140         date = Date('2000-02-28.22:58:59') + Interval('00:00:3661')
141         ae(str(date), '2000-02-29.00:00:00')
142         date = Date('2001-02-28.22:58:59') + Interval('00:00:3661')
143         ae(str(date), '2001-03-01.00:00:00')
144         date = Date('2001-03-01.00:00:00') + Interval('150y')
145         ae(str(date), '2151-03-01.00:00:00')
147     def testOffsetSub(self):
148         ae = self.assertEqual
149         date = Date('2000-12-01') - Interval('- 1d')
151         date = Date('2000-01-01') - Interval('- 2y 2m')
152         ae(str(date), '2002-03-01.00:00:00')
153         date = Date('2000-01-01') - Interval('2m')
154         ae(str(date), '1999-11-01.00:00:00')
156         date = Date('2000-03-01') - Interval('60d')
157         ae(str(date), '2000-01-01.00:00:00')
158         date = Date('2001-03-02') - Interval('60d')
159         ae(str(date), '2001-01-01.00:00:00')
161         date = Date('2000-02-29.00:00:00') - Interval('00:00:01')
162         ae(str(date), '2000-02-28.23:59:59')
163         date = Date('2001-03-01.00:00:00') - Interval('00:00:01')
164         ae(str(date), '2001-02-28.23:59:59')
166         date = Date('2000-02-29.00:00:00') - Interval('00:01:01')
167         ae(str(date), '2000-02-28.23:58:59')
168         date = Date('2001-03-01.00:00:00') - Interval('00:01:01')
169         ae(str(date), '2001-02-28.23:58:59')
171         date = Date('2000-02-29.00:00:00') - Interval('01:01:01')
172         ae(str(date), '2000-02-28.22:58:59')
173         date = Date('2001-03-01.00:00:00') - Interval('01:01:01')
174         ae(str(date), '2001-02-28.22:58:59')
176         date = Date('2000-02-29.00:00:00') - Interval('00:00:3661')
177         ae(str(date), '2000-02-28.22:58:59')
178         date = Date('2001-03-01.00:00:00') - Interval('00:00:3661')
179         ae(str(date), '2001-02-28.22:58:59')
180         date = Date('2001-03-01.00:00:00') - Interval('150y')
181         ae(str(date), '1851-03-01.00:00:00')
183     def testDateLocal(self):
184         ae = self.assertEqual
185         date = Date("02:42:20")
186         date = date.local(10)
187         y, m, d, x, x, x, x, x, x = time.gmtime(time.time())
188         ae(str(date), '%s-%02d-%02d.12:42:20'%(y, m, d))
190     def testIntervalInit(self):
191         ae = self.assertEqual
192         ae(str(Interval('3y')), '+ 3y')
193         ae(str(Interval('2 y 1 m')), '+ 2y 1m')
194         ae(str(Interval('1m 25d')), '+ 1m 25d')
195         ae(str(Interval('-2w 3 d ')), '- 17d')
196         ae(str(Interval(' - 1 d 2:50 ')), '- 1d 2:50')
197         ae(str(Interval(' 14:00 ')), '+ 14:00')
198         ae(str(Interval(' 0:04:33 ')), '+ 0:04:33')
199         ae(str(Interval(8.*3600)), '+ 8:00')
201     def testIntervalInitDate(self):
202         ae = self.assertEqual
203         now = Date('.')
204         now.hour = now.minute = now.second = 0
205         then = now + Interval('2d')
206         ae((Interval(str(then))), Interval('- 2d'))
207         then = now - Interval('2d')
208         ae(Interval(str(then)), Interval('+ 2d'))
210     def testIntervalAddMonthBoundary(self):
211         # force the transition over a month boundary
212         now = Date('2003-10-30.00:00:00')
213         then = now + Interval('2d')
214         self.assertEqual(str(then), '2003-11-01.00:00:00')
215         now = Date('2004-02-28.00:00:00')
216         then = now + Interval('1d')
217         self.assertEqual(str(then), '2004-02-29.00:00:00')
218         now = Date('2003-02-28.00:00:00')
219         then = now + Interval('1d')
220         self.assertEqual(str(then), '2003-03-01.00:00:00')
221         now = Date('2003-01-01.00:00:00')
222         then = now + Interval('59d')
223         self.assertEqual(str(then), '2003-03-01.00:00:00')
224         now = Date('2004-01-01.00:00:00')
225         then = now + Interval('59d')
226         self.assertEqual(str(then), '2004-02-29.00:00:00')
228     def testIntervalSubtractMonthBoundary(self):
229         # force the transition over a month boundary
230         now = Date('2003-11-01.00:00:00')
231         then = now - Interval('2d')
232         self.assertEqual(str(then), '2003-10-30.00:00:00')
233         now = Date('2004-02-29.00:00:00')
234         then = now - Interval('1d')
235         self.assertEqual(str(then), '2004-02-28.00:00:00')
236         now = Date('2003-03-01.00:00:00')
237         then = now - Interval('1d')
238         self.assertEqual(str(then), '2003-02-28.00:00:00')
239         now = Date('2003-03-01.00:00:00')
240         then = now - Interval('59d')
241         self.assertEqual(str(then), '2003-01-01.00:00:00')
242         now = Date('2004-02-29.00:00:00')
243         then = now - Interval('59d')
244         self.assertEqual(str(then), '2004-01-01.00:00:00')
246     def testIntervalAddYearBoundary(self):
247         # force the transition over a year boundary
248         now = Date('2003-12-30.00:00:00')
249         then = now + Interval('2d')
250         self.assertEqual(str(then), '2004-01-01.00:00:00')
251         now = Date('2003-01-01.00:00:00')
252         then = now + Interval('365d')
253         self.assertEqual(str(then), '2004-01-01.00:00:00')
254         now = Date('2004-01-01.00:00:00')
255         then = now + Interval('366d')
256         self.assertEqual(str(then), '2005-01-01.00:00:00')
258     def testIntervalSubtractYearBoundary(self):
259         # force the transition over a year boundary
260         now = Date('2003-01-01.00:00:00')
261         then = now - Interval('2d')
262         self.assertEqual(str(then), '2002-12-30.00:00:00')
263         now = Date('2004-02-01.00:00:00')
264         then = now - Interval('365d')
265         self.assertEqual(str(then), '2003-02-01.00:00:00')
266         now = Date('2005-02-01.00:00:00')
267         then = now - Interval('365d')
268         self.assertEqual(str(then), '2004-02-02.00:00:00')
270     def testDateSubtract(self):
271         # These are thoroughly broken right now.
272         i = Date('2003-03-15.00:00:00') - Date('2003-03-10.00:00:00')
273         self.assertEqual(i, Interval('5d'))
274         i = Date('2003-02-01.00:00:00') - Date('2003-03-01.00:00:00')
275         self.assertEqual(i, Interval('-28d'))
276         i = Date('2003-03-01.00:00:00') - Date('2003-02-01.00:00:00')
277         self.assertEqual(i, Interval('28d'))
278         i = Date('2003-03-03.00:00:00') - Date('2003-02-01.00:00:00')
279         self.assertEqual(i, Interval('30d'))
280         i = Date('2003-03-03.00:00:00') - Date('2002-02-01.00:00:00')
281         self.assertEqual(i, Interval('395d'))
282         i = Date('2003-03-03.00:00:00') - Date('2003-04-01.00:00:00')
283         self.assertEqual(i, Interval('-29d'))
284         i = Date('2003-03-01.00:00:00') - Date('2003-02-01.00:00:00')
285         self.assertEqual(i, Interval('28d'))
286         # force the transition over a year boundary
287         i = Date('2003-01-01.00:00:00') - Date('2002-01-01.00:00:00')
288         self.assertEqual(i, Interval('365d'))
289         i = Date('1952-01-01') - Date('1953-01-01')
290         self.assertEqual(i, Interval('-366d'))
291         i = Date('1953-01-01') - Date('1952-01-01')
292         self.assertEqual(i, Interval('366d'))
294     def testIntervalAdd(self):
295         ae = self.assertEqual
296         ae(str(Interval('1y') + Interval('1y')), '+ 2y')
297         ae(str(Interval('1y') + Interval('1m')), '+ 1y 1m')
298         ae(str(Interval('1y') + Interval('2:40')), '+ 1y 2:40')
299         ae(str(Interval('1y') + Interval('- 1y')), '00:00')
300         ae(str(Interval('- 1y') + Interval('1y')), '00:00')
301         ae(str(Interval('- 1y') + Interval('- 1y')), '- 2y')
302         ae(str(Interval('1y') + Interval('- 1m')), '+ 11m')
303         ae(str(Interval('1:00') + Interval('1:00')), '+ 2:00')
304         ae(str(Interval('0:50') + Interval('0:50')), '+ 1:40')
305         ae(str(Interval('1:50') + Interval('- 1:50')), '00:00')
306         ae(str(Interval('- 1:50') + Interval('1:50')), '00:00')
307         ae(str(Interval('- 1:50') + Interval('- 1:50')), '- 3:40')
308         ae(str(Interval('1:59:59') + Interval('00:00:01')), '+ 2:00')
309         ae(str(Interval('2:00') + Interval('- 00:00:01')), '+ 1:59:59')
311     def testIntervalSub(self):
312         ae = self.assertEqual
313         ae(str(Interval('1y') - Interval('- 1y')), '+ 2y')
314         ae(str(Interval('1y') - Interval('- 1m')), '+ 1y 1m')
315         ae(str(Interval('1y') - Interval('- 2:40')), '+ 1y 2:40')
316         ae(str(Interval('1y') - Interval('1y')), '00:00')
317         ae(str(Interval('1y') - Interval('1m')), '+ 11m')
318         ae(str(Interval('1:00') - Interval('- 1:00')), '+ 2:00')
319         ae(str(Interval('0:50') - Interval('- 0:50')), '+ 1:40')
320         ae(str(Interval('1:50') - Interval('1:50')), '00:00')
321         ae(str(Interval('1:59:59') - Interval('- 00:00:01')), '+ 2:00')
322         ae(str(Interval('2:00') - Interval('00:00:01')), '+ 1:59:59')
324     def testOverflow(self):
325         ae = self.assertEqual
326         ae(fixTimeOverflow((1,0,0,0, 0, 0, 60)), (1,0,0,0, 0, 1, 0))
327         ae(fixTimeOverflow((1,0,0,0, 0, 0, 100)), (1,0,0,0, 0, 1, 40))
328         ae(fixTimeOverflow((1,0,0,0, 0, 0, 60*60)), (1,0,0,0, 1, 0, 0))
329         ae(fixTimeOverflow((1,0,0,0, 0, 0, 24*60*60)), (1,0,0,1, 0, 0, 0))
330         ae(fixTimeOverflow((1,0,0,0, 0, 0, -1)), (-1,0,0,0, 0, 0, 1))
331         ae(fixTimeOverflow((1,0,0,0, 0, 0, -100)), (-1,0,0,0, 0, 1, 40))
332         ae(fixTimeOverflow((1,0,0,0, 0, 0, -60*60)), (-1,0,0,0, 1, 0, 0))
333         ae(fixTimeOverflow((1,0,0,0, 0, 0, -24*60*60)), (-1,0,0,1, 0, 0, 0))
334         ae(fixTimeOverflow((-1,0,0,0, 0, 0, 1)), (-1,0,0,0, 0, 0, 1))
335         ae(fixTimeOverflow((-1,0,0,0, 0, 0, 100)), (-1,0,0,0, 0, 1, 40))
336         ae(fixTimeOverflow((-1,0,0,0, 0, 0, 60*60)), (-1,0,0,0, 1, 0, 0))
337         ae(fixTimeOverflow((-1,0,0,0, 0, 0, 24*60*60)), (-1,0,0,1, 0, 0, 0))
339     def testDivision(self):
340         ae = self.assertEqual
341         ae(str(Interval('1y')/2), '+ 6m')
342         ae(str(Interval('1:00')/2), '+ 0:30')
343         ae(str(Interval('00:01')/2), '+ 0:00:30')
345     def testSorting(self):
346         ae = self.assertEqual
347         i1 = Interval('1y')
348         i2 = Interval('1d')
349         l = [i1, i2]; l.sort()
350         ae(l, [i2, i1])
351         l = [i2, i1]; l.sort()
352         ae(l, [i2, i1])
353         i1 = Interval('- 2d')
354         i2 = Interval('1d')
355         l = [i1, i2]; l.sort()
356         ae(l, [i1, i2])
358         i1 = Interval("1:20")
359         i2 = Interval("2d")
360         i3 = Interval("3:30")
361         l = [i1, i2, i3]; l.sort()
362         ae(l, [i1, i3, i2])
364     def testGranularity(self):
365         ae = self.assertEqual
366         ae(str(Date('2003-2-12', add_granularity=1)), '2003-02-12.23:59:59')
367         ae(str(Date('2003-1-1.23:00', add_granularity=1)), '2003-01-01.23:00:59')
368         ae(str(Date('2003', add_granularity=1)), '2003-12-31.23:59:59')
369         ae(str(Date('2003-5', add_granularity=1)), '2003-05-31.23:59:59')
370         ae(str(Date('2003-12', add_granularity=1)), '2003-12-31.23:59:59')
371         ae(str(Interval('+1w', add_granularity=1)), '+ 14d')
372         ae(str(Interval('-2m 3w', add_granularity=1)), '- 2m 14d')
374     def testIntervalPretty(self):
375         def ae(spec, pretty):
376             self.assertEqual(Interval(spec).pretty(), pretty)
377         ae('2y', 'in 2 years')
378         ae('1y', 'in 1 year')
379         ae('2m', 'in 2 months')
380         ae('1m 30d', 'in 2 months')
381         ae('60d', 'in 2 months')
382         ae('59d', 'in 1 month')
383         ae('1m', 'in 1 month')
384         ae('29d', 'in 1 month')
385         ae('28d', 'in 4 weeks')
386         ae('8d', 'in 1 week')
387         ae('7d', 'in 7 days')
388         ae('1w', 'in 7 days')
389         ae('2d', 'in 2 days')
390         ae('1d', 'tomorrow')
391         ae('02:00:00', 'in 2 hours')
392         ae('01:59:00', 'in 1 3/4 hours')
393         ae('01:45:00', 'in 1 3/4 hours')
394         ae('01:30:00', 'in 1 1/2 hours')
395         ae('01:29:00', 'in 1 1/4 hours')
396         ae('01:00:00', 'in an hour')
397         ae('00:30:00', 'in 1/2 an hour')
398         ae('00:15:00', 'in 1/4 hour')
399         ae('00:02:00', 'in 2 minutes')
400         ae('00:01:00', 'in 1 minute')
401         ae('00:00:30', 'in a moment')
402         ae('-00:00:30', 'just now')
403         ae('-1d', 'yesterday')
404         ae('-1y', '1 year ago')
405         ae('-2y', '2 years ago')
407     def testPyDatetime(self):
408         d = datetime.datetime.now()
409         Date(d)
410         toomuch = datetime.MAXYEAR + 1
411         self.assertRaises(ValueError, Date, (toomuch, 1, 1, 0, 0, 0, 0, 1, -1))
413     def testSimpleTZ(self):
414         ae = self.assertEqual
415         # local to utc
416         date = Date('2006-04-04.12:00:00', 2)
417         ae(str(date), '2006-04-04.10:00:00')
418         # utc to local
419         date = Date('2006-04-04.10:00:00')
420         date = date.local(2)
421         ae(str(date), '2006-04-04.12:00:00')
422         # from Date instance
423         date = Date('2006-04-04.12:00:00')
424         date = Date(date, 2)
425         ae(str(date), '2006-04-04.10:00:00')
427     def testTimestamp(self):
428         ae = self.assertEqual
429         date = Date('2038')
430         ae(date.timestamp(), 2145916800)
431         date = Date('1902')
432         ae(date.timestamp(), -2145916800)
433         date = Date(time.gmtime(0))
434         ae(date.timestamp(), 0)
435         ae(str(date), '1970-01-01.00:00:00')
436         date = Date(time.gmtime(0x7FFFFFFF))
437         ae(date.timestamp(), 2147483647)
438         ae(str(date), '2038-01-19.03:14:07')
439         date = Date('1901-12-13.20:45:52')
440         ae(date.timestamp(), -0x80000000L)
441         ae(str(date), '1901-12-13.20:45:52')
442         date = Date('9999')
443         ae (date.timestamp(), 253370764800.0)
444         date = Date('0033')
445         ae (date.timestamp(), -61125753600.0)
446         ae(str(date), '0033-01-01.00:00:00')
448 class TimezoneTestCase(unittest.TestCase):
450     def testTZ(self):
451         ae = self.assertEqual
452         tz = 'Europe/Warsaw'
454         # local to utc, DST
455         date = Date('2006-04-04.12:00:00', tz)
456         ae(str(date), '2006-04-04.10:00:00')
458         # local to utc, no DST
459         date = Date('2006-01-01.12:00:00', tz)
460         ae(str(date), '2006-01-01.11:00:00')
462         # utc to local, DST
463         date = Date('2006-04-04.10:00:00')
464         date = date.local(tz)
465         ae(str(date), '2006-04-04.12:00:00')
467         # utc to local, no DST
468         date = Date('2006-01-01.10:00:00')
469         date = date.local(tz)
470         ae(str(date), '2006-01-01.11:00:00')
472         date = Date('2006-04-04.12:00:00')
473         date = Date(date, tz)
474         ae(str(date), '2006-04-04.10:00:00')
475         date = Date('2006-01-01.12:00:00')
476         date = Date(date, tz)
477         ae(str(date), '2006-01-01.11:00:00')
480 class RangeTestCase(unittest.TestCase):
482     def testRange(self):
483         ae = self.assertEqual
484         r = Range('2006', Date)
485         ae(str(r.from_value), '2006-01-01.00:00:00')
486         ae(str(r.to_value), '2006-12-31.23:59:59')
487         for i in range(1, 13):
488             r = Range('2006-%02d'%i, Date)
489             ae(str(r.from_value), '2006-%02d-01.00:00:00'%i)
490             ae(str(r.to_value), '2006-%02d-%02d.23:59:59'%(i,
491                 calendar.mdays[i]))
494 def test_suite():
495     suite = unittest.TestSuite()
496     suite.addTest(unittest.makeSuite(DateTestCase))
497     suite.addTest(unittest.makeSuite(RangeTestCase))
498     try:
499         import pytz
500     except ImportError:
501         pass
502     else:
503         suite.addTest(unittest.makeSuite(TimezoneTestCase))
504     return suite
506 if __name__ == '__main__':
507     runner = unittest.TextTestRunner()
508     unittest.main(testRunner=runner)
510 # vim: set filetype=python sts=4 sw=4 et si :