summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0eb14c0)
raw | patch | inline | side by side (parent: 0eb14c0)
author | anthonybaxter <anthonybaxter@57a73879-2fb5-44c3-a270-3262357dd7e2> | |
Mon, 3 Nov 2003 10:23:06 +0000 (10:23 +0000) | ||
committer | anthonybaxter <anthonybaxter@57a73879-2fb5-44c3-a270-3262357dd7e2> | |
Mon, 3 Nov 2003 10:23:06 +0000 (10:23 +0000) |
fixing a couple of the tests to actually reflect the calendar used on
my planet rather than where-ever Richard was when he wrote the test <wink>
The basic problem was that when going backwards, the code was adding
the days of the current month, rather than the previous month.
There's still a bug in the testDateSubtract that I'll fix next.
Bugfix candidate (probably)
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1954 57a73879-2fb5-44c3-a270-3262357dd7e2
my planet rather than where-ever Richard was when he wrote the test <wink>
The basic problem was that when going backwards, the code was adding
the days of the current month, rather than the previous month.
There's still a bug in the testDateSubtract that I'll fix next.
Bugfix candidate (probably)
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1954 57a73879-2fb5-44c3-a270-3262357dd7e2
roundup/date.py | patch | blob | history | |
test/test_dates.py | patch | blob | history |
diff --git a/roundup/date.py b/roundup/date.py
index 365aa80b07cc670a641400ea896e0f9a753f8cd0..69c9935bb3fbd9286104461fec2d672ef25351ec 100644 (file)
--- a/roundup/date.py
+++ b/roundup/date.py
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
#
-# $Id: date.py,v 1.54 2003-04-23 11:48:05 richard Exp $
+# $Id: date.py,v 1.55 2003-11-03 10:23:05 anthonybaxter Exp $
__doc__ = """
Date, time and time interval handling.
if month > 12: year += 1; month -= 12
# now do the days, now that we know what month we're in
- mdays = calendar.mdays
- if month == 2 and calendar.isleap(year): month_days = 29
- else: month_days = mdays[month]
- while month < 1 or month > 12 or day < 0 or day > month_days:
+ def get_mdays(year,month):
+ if month == 2 and calendar.isleap(year): return 29
+ else: return calendar.mdays[month]
+
+ while month < 1 or month > 12 or day < 0 or day > get_mdays(year,month):
# now to day under/over
- if day < 0: month -= 1; day += month_days
- elif day > month_days: month += 1; day -= month_days
+ if day < 0:
+ # When going backwards, decrement month, then increment days
+ month -= 1
+ day += get_mdays(year,month)
+ elif day > get_mdays(year,month):
+ # When going forwards, decrement days, then increment month
+ day -= get_mdays(year,month)
+ month += 1
# possibly fix up the month so we're within range
while month < 1 or month > 12:
- if month < 1: year -= 1; month += 12
+ if month < 1: year -= 1; month += 12 ; day += 31
if month > 12: year += 1; month -= 12
- # re-figure the number of days for this month
- if month == 2 and calendar.isleap(year): month_days = 29
- else: month_days = mdays[month]
return (year, month, day, hour, minute, second, 0, 0, 0)
def applyInterval(self, interval):
diff --git a/test/test_dates.py b/test/test_dates.py
index bf594e8c5fdb2dccfbf0f2dd2f1cfa49160d43e4..a43a7b1d4e3319ae217dad4ce9a3ee34d472168a 100644 (file)
--- a/test/test_dates.py
+++ b/test/test_dates.py
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
#
-# $Id: test_dates.py,v 1.26 2003-11-02 09:27:50 richard Exp $
+# $Id: test_dates.py,v 1.27 2003-11-03 10:23:06 anthonybaxter Exp $
import unittest, time
self.assertEqual(str(then), '2004-02-28.00:00:00')
now = Date('2003-03-01.00:00:00')
then = now - Interval('1d')
- self.assertEqual(str(then), '2003-02-08.00:00:00')
+ self.assertEqual(str(then), '2003-02-28.00:00:00')
now = Date('2003-03-01.00:00:00')
then = now - Interval('59d')
self.assertEqual(str(then), '2003-01-01.00:00:00')
then = now + Interval('2d')
self.assertEqual(str(then), '2004-01-01.00:00:00')
now = Date('2003-01-01.00:00:00')
- then = now + Interval('364d')
+ then = now + Interval('365d')
self.assertEqual(str(then), '2004-01-01.00:00:00')
now = Date('2004-01-01.00:00:00')
- then = now + Interval('365d')
+ then = now + Interval('366d')
self.assertEqual(str(then), '2005-01-01.00:00:00')
def testIntervalSubtractYearBoundary(self):