Code

Fixed bug in unit test ;)
[roundup.git] / test / test_dates.py
1 # $Id: test_dates.py,v 1.4 2001-07-29 23:32:13 richard Exp $ 
3 import unittest, time
5 from roundup.date import Date, Interval
7 class DateTestCase(unittest.TestCase):
8     def testDateInterval(self):
9         ae = self.assertEqual
10         date = Date("2000-06-26.00:34:02 + 2d")
11         ae(str(date), '2000-06-28.00:34:02')
12         date = Date("2000-02-27 + 2d")
13         ae(str(date), '2000-02-29.00:00:00')
14         date = Date("2001-02-27 + 2d")
15         ae(str(date), '2001-03-01.00:00:00')
17     def testDate(self):
18         ae = self.assertEqual
19         date = Date("2000-04-17")
20         ae(str(date), '2000-04-17.00:00:00')
21         date = Date("01-25")
22         y, m, d, x, x, x, x, x, x = time.gmtime()
23         ae(str(date), '%s-01-25.00:00:00'%y)
24         date = Date("2000-04-17.03:45")
25         ae(str(date), '2000-04-17.03:45:00')
26         date = Date("08-13.22:13")
27         ae(str(date), '%s-08-13.22:13:00'%y)
28         date = Date("11-07.09:32:43")
29         ae(str(date), '%s-11-07.09:32:43'%y)
30         date = Date("14:25")
31         ae(str(date), '%s-%02d-%02d.14:25:00'%(y, m, d))
32         date = Date("8:47:11")
33         ae(str(date), '%s-%02d-%02d.08:47:11'%(y, m, d))
35     def testOffset(self):
36         ae = self.assertEqual
37         date = Date("2000-04-17", -5)
38         ae(str(date), '2000-04-17.00:00:00')
39         date = Date("01-25", -5)
40         y, m, d, x, x, x, x, x, x = time.gmtime()
41         ae(str(date), '%s-01-25.00:00:00'%y)
42         date = Date("2000-04-17.03:45", -5)
43         ae(str(date), '2000-04-17.08:45:00')
44         date = Date("08-13.22:13", -5)
45         ae(str(date), '%s-08-14.03:13:00'%y)
46         date = Date("11-07.09:32:43", -5)
47         ae(str(date), '%s-11-07.14:32:43'%y)
48         date = Date("14:25", -5)
49         ae(str(date), '%s-%02d-%02d.19:25:00'%(y, m, d))
50         date = Date("8:47:11", -5)
51         ae(str(date), '%s-%02d-%02d.13:47:11'%(y, m, d))
53     def testInterval(self):
54         ae = self.assertEqual
55         ae(str(Interval('3y')), '+ 3y')
56         ae(str(Interval('2 y 1 m')), '+ 2y 1m')
57         ae(str(Interval('1m 25d')), '+ 1m 25d')
58         ae(str(Interval('-2w 3 d ')), '- 17d')
59         ae(str(Interval(' - 1 d 2:50 ')), '- 1d 2:50')
60         ae(str(Interval(' 14:00 ')), '+ 14:00')
61         ae(str(Interval(' 0:04:33 ')), '+ 0:04:33')
63 def suite():
64    return unittest.makeSuite(DateTestCase, 'test')
67 #
68 # $Log: not supported by cvs2svn $
69 # Revision 1.3  2001/07/29 07:01:39  richard
70 # Added vim command to all source so that we don't get no steenkin' tabs :)
71 #
72 # Revision 1.2  2001/07/29 06:42:20  richard
73 # Added Interval tests.
74 #
75 # Revision 1.1  2001/07/27 06:55:07  richard
76 # moving tests -> test
77 #
78 # Revision 1.2  2001/07/25 04:34:31  richard
79 # Added id and log to tests files...
80 #
81 #
82 # vim: set filetype=python ts=4 sw=4 et si