comparison test/test_dates.py @ 1884:dc55a195722d

woo, failing date arithmetic tests
author Richard Jones <richard@users.sourceforge.net>
date Sun, 02 Nov 2003 09:27:50 +0000
parents f63aa57386b0
children deba54ed724f
comparison
equal deleted inserted replaced
1883:043e1b699047 1884:dc55a195722d
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.25 2003-10-25 22:53:26 richard Exp $ 18 # $Id: test_dates.py,v 1.26 2003-11-02 09:27:50 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
175 then = now + Interval('2d') 175 then = now + Interval('2d')
176 ae(str(Interval(str(then))), '+ 2d') 176 ae(str(Interval(str(then))), '+ 2d')
177 then = now - Interval('2d') 177 then = now - Interval('2d')
178 ae(str(Interval(str(then))), '- 2d') 178 ae(str(Interval(str(then))), '- 2d')
179 179
180 def testIntervalAddMonthBoundary(self):
181 # force the transition over a month boundary
182 now = Date('2003-10-30.00:00:00')
183 then = now + Interval('2d')
184 self.assertEqual(str(then), '2003-11-01.00:00:00')
185 now = Date('2004-02-28.00:00:00')
186 then = now + Interval('1d')
187 self.assertEqual(str(then), '2004-02-29.00:00:00')
188 now = Date('2003-02-28.00:00:00')
189 then = now + Interval('1d')
190 self.assertEqual(str(then), '2003-03-01.00:00:00')
191 now = Date('2003-01-01.00:00:00')
192 then = now + Interval('59d')
193 self.assertEqual(str(then), '2003-03-01.00:00:00')
194 now = Date('2004-01-01.00:00:00')
195 then = now + Interval('59d')
196 self.assertEqual(str(then), '2004-02-29.00:00:00')
197
198 def testIntervalSubtractMonthBoundary(self):
199 # force the transition over a month boundary
200 now = Date('2003-11-01.00:00:00')
201 then = now - Interval('2d')
202 self.assertEqual(str(then), '2003-10-30.00:00:00')
203 now = Date('2004-02-29.00:00:00')
204 then = now - Interval('1d')
205 self.assertEqual(str(then), '2004-02-28.00:00:00')
206 now = Date('2003-03-01.00:00:00')
207 then = now - Interval('1d')
208 self.assertEqual(str(then), '2003-02-08.00:00:00')
209 now = Date('2003-03-01.00:00:00')
210 then = now - Interval('59d')
211 self.assertEqual(str(then), '2003-01-01.00:00:00')
212 now = Date('2004-02-29.00:00:00')
213 then = now - Interval('59d')
214 self.assertEqual(str(then), '2004-01-01.00:00:00')
215
216 def testIntervalAddYearBoundary(self):
217 # force the transition over a year boundary
218 now = Date('2003-12-30.00:00:00')
219 then = now + Interval('2d')
220 self.assertEqual(str(then), '2004-01-01.00:00:00')
221 now = Date('2003-01-01.00:00:00')
222 then = now + Interval('364d')
223 self.assertEqual(str(then), '2004-01-01.00:00:00')
224 now = Date('2004-01-01.00:00:00')
225 then = now + Interval('365d')
226 self.assertEqual(str(then), '2005-01-01.00:00:00')
227
228 def testIntervalSubtractYearBoundary(self):
229 # force the transition over a year boundary
230 now = Date('2003-01-01.00:00:00')
231 then = now - Interval('2d')
232 self.assertEqual(str(then), '2002-12-30.00:00:00')
233 now = Date('2004-02-01.00:00:00')
234 then = now - Interval('365d')
235 self.assertEqual(str(then), '2003-02-01.00:00:00')
236 now = Date('2005-02-01.00:00:00')
237 then = now - Interval('365d')
238 self.assertEqual(str(then), '2004-02-02.00:00:00')
239
240 def testDateSubtract(self):
241 # force the transition over a year boundary
242 i = Date('2003-01-01.00:00:00') - Date('2002-01-01.00:00:00')
243 self.assertEqual(str(i).strip(), '1y')
244
180 def testIntervalAdd(self): 245 def testIntervalAdd(self):
181 ae = self.assertEqual 246 ae = self.assertEqual
182 ae(str(Interval('1y') + Interval('1y')), '+ 2y') 247 ae(str(Interval('1y') + Interval('1y')), '+ 2y')
183 ae(str(Interval('1y') + Interval('1m')), '+ 1y 1m') 248 ae(str(Interval('1y') + Interval('1m')), '+ 1y 1m')
184 ae(str(Interval('1y') + Interval('2:40')), '+ 1y 2:40') 249 ae(str(Interval('1y') + Interval('2:40')), '+ 1y 2:40')

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