From 357a8034c643e11ff123d44e5472b149e6fa76fa Mon Sep 17 00:00:00 2001 From: richard Date: Thu, 6 Mar 2003 06:12:30 +0000 Subject: [PATCH] oops, Interval sorting ignored sign git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1571 57a73879-2fb5-44c3-a270-3262357dd7e2 --- roundup/date.py | 7 ++++--- test/test_dates.py | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/roundup/date.py b/roundup/date.py index 04bcbda..9c47917 100644 --- a/roundup/date.py +++ b/roundup/date.py @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: date.py,v 1.44 2003-03-06 02:33:56 richard Exp $ +# $Id: date.py,v 1.45 2003-03-06 06:12:30 richard Exp $ __doc__ = """ Date, time and time interval handling. @@ -355,11 +355,12 @@ class Interval: """Compare this interval to another interval.""" if other is None: return 1 - for attr in ('year', 'month', 'day', 'hour', 'minute', 'second'): + for attr in 'sign year month day hour minute second'.split(): if not hasattr(other, attr): return 1 r = cmp(getattr(self, attr), getattr(other, attr)) - if r: return r + if r: + return r return 0 def __str__(self): diff --git a/test/test_dates.py b/test/test_dates.py index f88212a..2223e3e 100644 --- a/test/test_dates.py +++ b/test/test_dates.py @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: test_dates.py,v 1.18 2003-03-06 02:33:57 richard Exp $ +# $Id: test_dates.py,v 1.19 2003-03-06 06:12:30 richard Exp $ import unittest, time @@ -210,6 +210,20 @@ class DateTestCase(unittest.TestCase): ae(str(Interval('1:00')/2), '+ 0:30') ae(str(Interval('00:01')/2), '+ 0:00:30') + def testSorting(self): + ae = self.assertEqual + i1 = Interval('1y') + i2 = Interval('1d') + l = [i1, i2]; l.sort() + ae(l, [i2, i1]) + l = [i2, i1]; l.sort() + ae(l, [i2, i1]) + i1 = Interval('- 2d') + i2 = Interval('1d') + l = [i1, i2]; l.sort() + ae(l, [i1, i2]) + + def suite(): return unittest.makeSuite(DateTestCase, 'test') -- 2.39.5