Skip to content

Commit ccce6b2

Browse files
author
Richard Jones
committed
woo, failing date arithmetic tests
1 parent a4cb8b7 commit ccce6b2

File tree

1 file changed

+66
-1
lines changed

1 file changed

+66
-1
lines changed

test/test_dates.py

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
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.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 $
1919

2020
import unittest, time
2121

@@ -177,6 +177,71 @@ def testIntervalInitDate(self):
177177
then = now - Interval('2d')
178178
ae(str(Interval(str(then))), '- 2d')
179179

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+
180245
def testIntervalAdd(self):
181246
ae = self.assertEqual
182247
ae(str(Interval('1y') + Interval('1y')), '+ 2y')

0 commit comments

Comments
 (0)