1515# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717#
18- # $Id: test_dates.py,v 1.15 2002-12-09 02:43:21 richard Exp $
18+ # $Id: test_dates.py,v 1.15.2.1 2003-03-06 04:37:51 richard Exp $
1919
2020import unittest , time
2121
22- from roundup .date import Date , Interval
22+ from roundup .date import Date , Interval , fixTimeOverflow
2323
2424class DateTestCase (unittest .TestCase ):
2525 def testDateInterval (self ):
@@ -56,10 +56,10 @@ def testDate(self):
5656 def testOffset (self ):
5757 ae = self .assertEqual
5858 date = Date ("2000-04-17" , - 5 )
59- ae (str (date ), '2000-04-17.00 :00:00' )
59+ ae (str (date ), '2000-04-17.05 :00:00' )
6060 date = Date ("01-25" , - 5 )
6161 y , m , d , x , x , x , x , x , x = time .gmtime (time .time ())
62- ae (str (date ), '%s-01-25.00 :00:00' % y )
62+ ae (str (date ), '%s-01-25.05 :00:00' % y )
6363 date = Date ("2000-04-17.03:45" , - 5 )
6464 ae (str (date ), '2000-04-17.08:45:00' )
6565 date = Date ("08-13.22:13" , - 5 )
@@ -71,7 +71,9 @@ def testOffset(self):
7171 date = Date ("8:47:11" , - 5 )
7272 ae (str (date ), '%s-%02d-%02d.13:47:11' % (y , m , d ))
7373
74- # now check calculations
74+ def testOffsetRandom (self ):
75+ ae = self .assertEqual
76+ # XXX unsure of the usefulness of these, they're pretty random
7577 date = Date ('2000-01-01' ) + Interval ('- 2y 2m' )
7678 ae (str (date ), '1997-11-01.00:00:00' )
7779 date = Date ('2000-01-01 - 2y 2m' )
@@ -86,7 +88,8 @@ def testOffset(self):
8688 date = Date ('2001-01-01' ) + Interval ('60d' )
8789 ae (str (date ), '2001-03-02.00:00:00' )
8890
89- # time additions
91+ def testOffsetAdd (self ):
92+ ae = self .assertEqual
9093 date = Date ('2000-02-28.23:59:59' ) + Interval ('00:00:01' )
9194 ae (str (date ), '2000-02-29.00:00:00' )
9295 date = Date ('2001-02-28.23:59:59' ) + Interval ('00:00:01' )
@@ -107,7 +110,8 @@ def testOffset(self):
107110 date = Date ('2001-02-28.22:58:59' ) + Interval ('00:00:3661' )
108111 ae (str (date ), '2001-03-01.00:00:00' )
109112
110- # now subtractions
113+ def testOffsetSub (self ):
114+ ae = self .assertEqual
111115 date = Date ('2000-01-01' ) - Interval ('- 2y 2m' )
112116 ae (str (date ), '2002-03-01.00:00:00' )
113117 date = Date ('2000-01-01' ) - Interval ('2m' )
@@ -138,12 +142,14 @@ def testOffset(self):
138142 date = Date ('2001-03-01.00:00:00' ) - Interval ('00:00:3661' )
139143 ae (str (date ), '2001-02-28.22:58:59' )
140144
141- # local()
145+ def testDateLocal (self ):
146+ ae = self .assertEqual
142147 date = Date ("02:42:20" )
143148 date = date .local (10 )
149+ y , m , d , x , x , x , x , x , x = time .gmtime (time .time ())
144150 ae (str (date ), '%s-%02d-%02d.12:42:20' % (y , m , d ))
145151
146- def testInterval (self ):
152+ def testIntervalInit (self ):
147153 ae = self .assertEqual
148154 ae (str (Interval ('3y' )), '+ 3y' )
149155 ae (str (Interval ('2 y 1 m' )), '+ 2y 1m' )
@@ -153,14 +159,56 @@ def testInterval(self):
153159 ae (str (Interval (' 14:00 ' )), '+ 14:00' )
154160 ae (str (Interval (' 0:04:33 ' )), '+ 0:04:33' )
155161
156- # __add__
157- # XXX these are fairly arbitrary and need fixing once the __add__
158- # code handles the odd cases more correctly
162+ def testIntervalAdd (self ):
163+ ae = self .assertEqual
159164 ae (str (Interval ('1y' ) + Interval ('1y' )), '+ 2y' )
160165 ae (str (Interval ('1y' ) + Interval ('1m' )), '+ 1y 1m' )
161166 ae (str (Interval ('1y' ) + Interval ('2:40' )), '+ 1y 2:40' )
162- ae (str (Interval ('1y' ) + Interval ('- 1y' )), '+' )
163- ae (str (Interval ('1y' ) + Interval ('- 1m' )), '+ 1y -1m' )
167+ ae (str (Interval ('1y' ) + Interval ('- 1y' )), '' )
168+ ae (str (Interval ('- 1y' ) + Interval ('1y' )), '' )
169+ ae (str (Interval ('- 1y' ) + Interval ('- 1y' )), '- 2y' )
170+ ae (str (Interval ('1y' ) + Interval ('- 1m' )), '+ 11m' )
171+ ae (str (Interval ('1:00' ) + Interval ('1:00' )), '+ 2:00' )
172+ ae (str (Interval ('0:50' ) + Interval ('0:50' )), '+ 1:40' )
173+ ae (str (Interval ('1:50' ) + Interval ('- 1:50' )), '' )
174+ ae (str (Interval ('- 1:50' ) + Interval ('1:50' )), '' )
175+ ae (str (Interval ('- 1:50' ) + Interval ('- 1:50' )), '- 3:40' )
176+ ae (str (Interval ('1:59:59' ) + Interval ('00:00:01' )), '+ 2:00' )
177+ ae (str (Interval ('2:00' ) + Interval ('- 00:00:01' )), '+ 1:59:59' )
178+
179+ def testIntervalSub (self ):
180+ ae = self .assertEqual
181+ ae (str (Interval ('1y' ) - Interval ('- 1y' )), '+ 2y' )
182+ ae (str (Interval ('1y' ) - Interval ('- 1m' )), '+ 1y 1m' )
183+ ae (str (Interval ('1y' ) - Interval ('- 2:40' )), '+ 1y 2:40' )
184+ ae (str (Interval ('1y' ) - Interval ('1y' )), '' )
185+ ae (str (Interval ('1y' ) - Interval ('1m' )), '+ 11m' )
186+ ae (str (Interval ('1:00' ) - Interval ('- 1:00' )), '+ 2:00' )
187+ ae (str (Interval ('0:50' ) - Interval ('- 0:50' )), '+ 1:40' )
188+ ae (str (Interval ('1:50' ) - Interval ('1:50' )), '' )
189+ ae (str (Interval ('1:59:59' ) - Interval ('- 00:00:01' )), '+ 2:00' )
190+ ae (str (Interval ('2:00' ) - Interval ('00:00:01' )), '+ 1:59:59' )
191+
192+ def testOverflow (self ):
193+ ae = self .assertEqual
194+ ae (fixTimeOverflow ((1 ,0 ,0 ,0 , 0 , 0 , 60 )), (1 ,0 ,0 ,0 , 0 , 1 , 0 ))
195+ ae (fixTimeOverflow ((1 ,0 ,0 ,0 , 0 , 0 , 100 )), (1 ,0 ,0 ,0 , 0 , 1 , 40 ))
196+ ae (fixTimeOverflow ((1 ,0 ,0 ,0 , 0 , 0 , 60 * 60 )), (1 ,0 ,0 ,0 , 1 , 0 , 0 ))
197+ ae (fixTimeOverflow ((1 ,0 ,0 ,0 , 0 , 0 , 24 * 60 * 60 )), (1 ,0 ,0 ,1 , 0 , 0 , 0 ))
198+ ae (fixTimeOverflow ((1 ,0 ,0 ,0 , 0 , 0 , - 1 )), (- 1 ,0 ,0 ,0 , 0 , 0 , 1 ))
199+ ae (fixTimeOverflow ((1 ,0 ,0 ,0 , 0 , 0 , - 100 )), (- 1 ,0 ,0 ,0 , 0 , 1 , 40 ))
200+ ae (fixTimeOverflow ((1 ,0 ,0 ,0 , 0 , 0 , - 60 * 60 )), (- 1 ,0 ,0 ,0 , 1 , 0 , 0 ))
201+ ae (fixTimeOverflow ((1 ,0 ,0 ,0 , 0 , 0 , - 24 * 60 * 60 )), (- 1 ,0 ,0 ,1 , 0 , 0 , 0 ))
202+ ae (fixTimeOverflow ((- 1 ,0 ,0 ,0 , 0 , 0 , 1 )), (- 1 ,0 ,0 ,0 , 0 , 0 , 1 ))
203+ ae (fixTimeOverflow ((- 1 ,0 ,0 ,0 , 0 , 0 , 100 )), (- 1 ,0 ,0 ,0 , 0 , 1 , 40 ))
204+ ae (fixTimeOverflow ((- 1 ,0 ,0 ,0 , 0 , 0 , 60 * 60 )), (- 1 ,0 ,0 ,0 , 1 , 0 , 0 ))
205+ ae (fixTimeOverflow ((- 1 ,0 ,0 ,0 , 0 , 0 , 24 * 60 * 60 )), (- 1 ,0 ,0 ,1 , 0 , 0 , 0 ))
206+
207+ def testDivision (self ):
208+ ae = self .assertEqual
209+ ae (str (Interval ('1y' )/ 2 ), '+ 6m' )
210+ ae (str (Interval ('1:00' )/ 2 ), '+ 0:30' )
211+ ae (str (Interval ('00:01' )/ 2 ), '+ 0:00:30' )
164212
165213def suite ():
166214 return unittest .makeSuite (DateTestCase , 'test' )
0 commit comments