Skip to content

Commit 0d82200

Browse files
author
Richard Jones
committed
oops, Interval sorting ignored sign
1 parent b76e9bb commit 0d82200

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

roundup/date.py

Lines changed: 4 additions & 3 deletions
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: date.py,v 1.44 2003-03-06 02:33:56 richard Exp $
18+
# $Id: date.py,v 1.45 2003-03-06 06:12:30 richard Exp $
1919

2020
__doc__ = """
2121
Date, time and time interval handling.
@@ -355,11 +355,12 @@ def __cmp__(self, other):
355355
"""Compare this interval to another interval."""
356356
if other is None:
357357
return 1
358-
for attr in ('year', 'month', 'day', 'hour', 'minute', 'second'):
358+
for attr in 'sign year month day hour minute second'.split():
359359
if not hasattr(other, attr):
360360
return 1
361361
r = cmp(getattr(self, attr), getattr(other, attr))
362-
if r: return r
362+
if r:
363+
return r
363364
return 0
364365

365366
def __str__(self):

test/test_dates.py

Lines changed: 15 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.18 2003-03-06 02:33:57 richard Exp $
18+
# $Id: test_dates.py,v 1.19 2003-03-06 06:12:30 richard Exp $
1919

2020
import unittest, time
2121

@@ -210,6 +210,20 @@ def testDivision(self):
210210
ae(str(Interval('1:00')/2), '+ 0:30')
211211
ae(str(Interval('00:01')/2), '+ 0:00:30')
212212

213+
def testSorting(self):
214+
ae = self.assertEqual
215+
i1 = Interval('1y')
216+
i2 = Interval('1d')
217+
l = [i1, i2]; l.sort()
218+
ae(l, [i2, i1])
219+
l = [i2, i1]; l.sort()
220+
ae(l, [i2, i1])
221+
i1 = Interval('- 2d')
222+
i2 = Interval('1d')
223+
l = [i1, i2]; l.sort()
224+
ae(l, [i1, i2])
225+
226+
213227
def suite():
214228
return unittest.makeSuite(DateTestCase, 'test')
215229

0 commit comments

Comments
 (0)