Code

Oops, there's 24 hours in a day, and subtraction of intervals now works
[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.11 2002-02-21 23:34:52 richard Exp $ 
20 import unittest, time
22 from roundup.date import Date, Interval
24 class DateTestCase(unittest.TestCase):
25     def testDateInterval(self):
26         ae = self.assertEqual
27         date = Date("2000-06-26.00:34:02 + 2d")
28         ae(str(date), '2000-06-28.00:34:02')
29         date = Date("2000-02-27 + 2d")
30         ae(str(date), '2000-02-29.00:00:00')
31         date = Date("2001-02-27 + 2d")
32         ae(str(date), '2001-03-01.00:00:00')
34     def testDate(self):
35         ae = self.assertEqual
36         date = Date("2000-04-17")
37         ae(str(date), '2000-04-17.00:00:00')
38         date = Date("2000-4-7")
39         ae(str(date), '2000-04-07.00:00:00')
40         date = Date("2000-4-17")
41         ae(str(date), '2000-04-17.00:00:00')
42         date = Date("01-25")
43         y, m, d, x, x, x, x, x, x = time.gmtime(time.time())
44         ae(str(date), '%s-01-25.00:00:00'%y)
45         date = Date("2000-04-17.03:45")
46         ae(str(date), '2000-04-17.03:45:00')
47         date = Date("08-13.22:13")
48         ae(str(date), '%s-08-13.22:13:00'%y)
49         date = Date("11-07.09:32:43")
50         ae(str(date), '%s-11-07.09:32:43'%y)
51         date = Date("14:25")
52         ae(str(date), '%s-%02d-%02d.14:25:00'%(y, m, d))
53         date = Date("8:47:11")
54         ae(str(date), '%s-%02d-%02d.08:47:11'%(y, m, d))
56     def testOffset(self):
57         ae = self.assertEqual
58         date = Date("2000-04-17", -5)
59         ae(str(date), '2000-04-17.00:00:00')
60         date = Date("01-25", -5)
61         y, m, d, x, x, x, x, x, x = time.gmtime(time.time())
62         ae(str(date), '%s-01-25.00:00:00'%y)
63         date = Date("2000-04-17.03:45", -5)
64         ae(str(date), '2000-04-17.08:45:00')
65         date = Date("08-13.22:13", -5)
66         ae(str(date), '%s-08-14.03:13:00'%y)
67         date = Date("11-07.09:32:43", -5)
68         ae(str(date), '%s-11-07.14:32:43'%y)
69         date = Date("14:25", -5)
70         ae(str(date), '%s-%02d-%02d.19:25:00'%(y, m, d))
71         date = Date("8:47:11", -5)
72         ae(str(date), '%s-%02d-%02d.13:47:11'%(y, m, d))
74         # now check calculations
75         date = Date('2000-01-01') + Interval('- 2y 2m')
76         ae(str(date), '1997-11-01.00:00:00')
77         date = Date('2000-01-01') + Interval('2m')
78         ae(str(date), '2000-03-01.00:00:00')
80         date = Date('2000-01-01') + Interval('60d')
81         ae(str(date), '2000-03-01.00:00:00')
82         date = Date('2001-01-01') + Interval('60d')
83         ae(str(date), '2001-03-02.00:00:00')
85         # time additions
86         date = Date('2000-02-28.23:59:59') + Interval('00:00:01')
87         ae(str(date), '2000-02-29.00:00:00')
88         date = Date('2001-02-28.23:59:59') + Interval('00:00:01')
89         ae(str(date), '2001-03-01.00:00:00')
91         date = Date('2000-02-28.23:58:59') + Interval('00:01:01')
92         ae(str(date), '2000-02-29.00:00:00')
93         date = Date('2001-02-28.23:58:59') + Interval('00:01:01')
94         ae(str(date), '2001-03-01.00:00:00')
96         date = Date('2000-02-28.22:58:59') + Interval('01:01:01')
97         ae(str(date), '2000-02-29.00:00:00')
98         date = Date('2001-02-28.22:58:59') + Interval('01:01:01')
99         ae(str(date), '2001-03-01.00:00:00')
101         date = Date('2000-02-28.22:58:59') + Interval('00:00:3661')
102         ae(str(date), '2000-02-29.00:00:00')
103         date = Date('2001-02-28.22:58:59') + Interval('00:00:3661')
104         ae(str(date), '2001-03-01.00:00:00')
106         # now subtractions
107         date = Date('2000-01-01') - Interval('- 2y 2m')
108         ae(str(date), '2002-03-01.00:00:00')
109         date = Date('2000-01-01') - Interval('2m')
110         ae(str(date), '1999-11-01.00:00:00')
112         date = Date('2000-03-01') - Interval('60d')
113         ae(str(date), '2000-01-01.00:00:00')
114         date = Date('2001-03-02') - Interval('60d')
115         ae(str(date), '2001-01-01.00:00:00')
117         date = Date('2000-02-29.00:00:00') - Interval('00:00:01')
118         ae(str(date), '2000-02-28.23:59:59')
119         date = Date('2001-03-01.00:00:00') - Interval('00:00:01')
120         ae(str(date), '2001-02-28.23:59:59')
122         date = Date('2000-02-29.00:00:00') - Interval('00:01:01')
123         ae(str(date), '2000-02-28.23:58:59')
124         date = Date('2001-03-01.00:00:00') - Interval('00:01:01')
125         ae(str(date), '2001-02-28.23:58:59')
127         date = Date('2000-02-29.00:00:00') - Interval('01:01:01')
128         ae(str(date), '2000-02-28.22:58:59')
129         date = Date('2001-03-01.00:00:00') - Interval('01:01:01')
130         ae(str(date), '2001-02-28.22:58:59')
132         date = Date('2000-02-29.00:00:00') - Interval('00:00:3661')
133         ae(str(date), '2000-02-28.22:58:59')
134         date = Date('2001-03-01.00:00:00') - Interval('00:00:3661')
135         ae(str(date), '2001-02-28.22:58:59')
137     def testInterval(self):
138         ae = self.assertEqual
139         ae(str(Interval('3y')), '+ 3y')
140         ae(str(Interval('2 y 1 m')), '+ 2y 1m')
141         ae(str(Interval('1m 25d')), '+ 1m 25d')
142         ae(str(Interval('-2w 3 d ')), '- 17d')
143         ae(str(Interval(' - 1 d 2:50 ')), '- 1d 2:50')
144         ae(str(Interval(' 14:00 ')), '+ 14:00')
145         ae(str(Interval(' 0:04:33 ')), '+ 0:04:33')
147 def suite():
148    return unittest.makeSuite(DateTestCase, 'test')
152 # $Log: not supported by cvs2svn $
153 # Revision 1.10  2002/02/21 23:11:45  richard
154 #  . fixed some problems in date calculations (calendar.py doesn't handle over-
155 #    and under-flow). Also, hour/minute/second intervals may now be more than
156 #    99 each.
158 # Revision 1.9  2002/02/21 06:57:39  richard
159 #  . Added popup help for classes using the classhelp html template function.
160 #    - add <display call="classhelp('priority', 'id,name,description')">
161 #      to an item page, and it generates a link to a popup window which displays
162 #      the id, name and description for the priority class. The description
163 #      field won't exist in most installations, but it will be added to the
164 #      default templates.
166 # Revision 1.8  2002/01/16 07:02:57  richard
167 #  . lots of date/interval related changes:
168 #    - more relaxed date format for input
170 # Revision 1.7  2001/08/13 23:01:53  richard
171 # fixed a 2.1-ism
173 # Revision 1.6  2001/08/07 00:24:43  richard
174 # stupid typo
176 # Revision 1.5  2001/08/07 00:15:51  richard
177 # Added the copyright/license notice to (nearly) all files at request of
178 # Bizar Software.
180 # Revision 1.4  2001/07/29 23:32:13  richard
181 # Fixed bug in unit test ;)
183 # Revision 1.3  2001/07/29 07:01:39  richard
184 # Added vim command to all source so that we don't get no steenkin' tabs :)
186 # Revision 1.2  2001/07/29 06:42:20  richard
187 # Added Interval tests.
189 # Revision 1.1  2001/07/27 06:55:07  richard
190 # moving tests -> test
192 # Revision 1.2  2001/07/25 04:34:31  richard
193 # Added id and log to tests files...
196 # vim: set filetype=python ts=4 sw=4 et si