Skip to content

Commit 39e0d41

Browse files
author
Johannes Gijsbers
committed
Add tests for Interval.pretty().
Fix 'ago' and 'in' not being added to years. Fix docstrings for emacs.
1 parent 42e2dcf commit 39e0d41

File tree

2 files changed

+42
-8
lines changed

2 files changed

+42
-8
lines changed

roundup/date.py

Lines changed: 7 additions & 7 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.56 2003-11-04 12:35:47 anthonybaxter Exp $
18+
# $Id: date.py,v 1.57 2003-11-19 22:53:15 jlgijsbers Exp $
1919

2020
__doc__ = """
2121
Date, time and time interval handling.
@@ -514,11 +514,11 @@ def __sub__(self, other):
514514
raise TypeError, "Can't add %r"%other
515515

516516
def __div__(self, other):
517-
''' Divide this interval by an int value.
517+
""" Divide this interval by an int value.
518518
519519
Can't divide years and months sensibly in the _same_
520520
calculation as days/time, so raise an error in that situation.
521-
'''
521+
"""
522522
try:
523523
other = float(other)
524524
except TypeError:
@@ -564,9 +564,9 @@ def pretty(self):
564564
'''
565565
if self.year:
566566
if self.year == 1:
567-
return _('1 year')
567+
s = _('1 year')
568568
else:
569-
return _('%(number)s years')%{'number': self.year}
569+
s = _('%(number)s years')%{'number': self.year}
570570
elif self.month or self.day > 13:
571571
days = (self.month * 30) + self.day
572572
if days > 28:
@@ -623,13 +623,13 @@ def serialise(self):
623623
self.day, self.hour, self.minute, self.second)
624624

625625
def fixTimeOverflow(time):
626-
''' Handle the overflow in the time portion (H, M, S) of "time":
626+
""" Handle the overflow in the time portion (H, M, S) of "time":
627627
(sign, y,m,d,H,M,S)
628628
629629
Overflow and underflow will at most affect the _days_ portion of
630630
the date. We do not overflow days to months as we don't know _how_
631631
to, generally.
632-
'''
632+
"""
633633
# XXX we could conceivably use this function for handling regular dates
634634
# XXX too - we just need to interrogate the month/year for the day
635635
# XXX overflow...

test/test_dates.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
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.29 2003-11-04 12:35:47 anthonybaxter Exp $
18+
# $Id: test_dates.py,v 1.30 2003-11-19 22:53:14 jlgijsbers Exp $
19+
from __future__ import nested_scopes
1920

2021
import unittest, time
2122

@@ -335,6 +336,39 @@ def testGranularity(self):
335336
ae(str(Date('2003-5', add_granularity=1)), '2003-05-31.23:59:59')
336337
ae(str(Interval('+1w', add_granularity=1)), '+ 14d')
337338
ae(str(Interval('-2m 3w', add_granularity=1)), '- 2m 14d')
339+
340+
def testIntervalPretty(self):
341+
def ae(spec, pretty):
342+
self.assertEqual(Interval(spec).pretty(), pretty)
343+
ae('2y', 'in 2 years')
344+
ae('1y', 'in 1 year')
345+
ae('2m', 'in 2 months')
346+
ae('1m 30d', 'in 2 months')
347+
ae('60d', 'in 2 months')
348+
ae('59d', 'in 1 month')
349+
ae('1m', 'in 1 month')
350+
ae('29d', 'in 1 month')
351+
ae('28d', 'in 4 weeks')
352+
ae('8d', 'in 1 week')
353+
ae('7d', 'in 7 days')
354+
ae('1w', 'in 7 days')
355+
ae('2d', 'in 2 days')
356+
ae('1d', 'tomorrow')
357+
ae('02:00:00', 'in 2 hours')
358+
ae('01:59:00', 'in 1 3/4 hours')
359+
ae('01:45:00', 'in 1 3/4 hours')
360+
ae('01:30:00', 'in 1 1/2 hours')
361+
ae('01:29:00', 'in 1 1/4 hours')
362+
ae('01:00:00', 'in an hour')
363+
ae('00:30:00', 'in 1/2 an hour')
364+
ae('00:15:00', 'in 1/4 hour')
365+
ae('00:02:00', 'in 2 minutes')
366+
ae('00:01:00', 'in 1 minute')
367+
ae('00:00:30', 'in a moment')
368+
ae('-00:00:30', 'just now')
369+
ae('-1d', 'yesterday')
370+
ae('-1y', '1 year ago')
371+
ae('-2y', '2 years ago')
338372

339373
def test_suite():
340374
suite = unittest.TestSuite()

0 commit comments

Comments
 (0)