summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ababf3e)
raw | patch | inline | side by side (parent: ababf3e)
author | jlgijsbers <jlgijsbers@57a73879-2fb5-44c3-a270-3262357dd7e2> | |
Wed, 19 Nov 2003 22:53:15 +0000 (22:53 +0000) | ||
committer | jlgijsbers <jlgijsbers@57a73879-2fb5-44c3-a270-3262357dd7e2> | |
Wed, 19 Nov 2003 22:53:15 +0000 (22:53 +0000) |
- Fix 'ago' and 'in' not being added to years.
- Fix docstrings for emacs.
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1999 57a73879-2fb5-44c3-a270-3262357dd7e2
- Fix docstrings for emacs.
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1999 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 d4f5f36d8acae0e51fd8d29120e530678631d579..b9fd398c160b56d844192fb778bb890e928838b5 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.56 2003-11-04 12:35:47 anthonybaxter Exp $
+# $Id: date.py,v 1.57 2003-11-19 22:53:15 jlgijsbers Exp $
__doc__ = """
Date, time and time interval handling.
raise TypeError, "Can't add %r"%other
def __div__(self, other):
- ''' Divide this interval by an int value.
+ """ Divide this interval by an int value.
Can't divide years and months sensibly in the _same_
calculation as days/time, so raise an error in that situation.
- '''
+ """
try:
other = float(other)
except TypeError:
'''
if self.year:
if self.year == 1:
- return _('1 year')
+ s = _('1 year')
else:
- return _('%(number)s years')%{'number': self.year}
+ s = _('%(number)s years')%{'number': self.year}
elif self.month or self.day > 13:
days = (self.month * 30) + self.day
if days > 28:
self.day, self.hour, self.minute, self.second)
def fixTimeOverflow(time):
- ''' Handle the overflow in the time portion (H, M, S) of "time":
+ """ Handle the overflow in the time portion (H, M, S) of "time":
(sign, y,m,d,H,M,S)
Overflow and underflow will at most affect the _days_ portion of
the date. We do not overflow days to months as we don't know _how_
to, generally.
- '''
+ """
# XXX we could conceivably use this function for handling regular dates
# XXX too - we just need to interrogate the month/year for the day
# XXX overflow...
diff --git a/test/test_dates.py b/test/test_dates.py
index d924ab310c8ccee1b01e730268324d9d0f06e35a..2c92acaaab33f2b26dd15d268ffc0c8006210d9f 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.29 2003-11-04 12:35:47 anthonybaxter Exp $
+# $Id: test_dates.py,v 1.30 2003-11-19 22:53:14 jlgijsbers Exp $
+from __future__ import nested_scopes
import unittest, time
ae(str(Date('2003-5', add_granularity=1)), '2003-05-31.23:59:59')
ae(str(Interval('+1w', add_granularity=1)), '+ 14d')
ae(str(Interval('-2m 3w', add_granularity=1)), '- 2m 14d')
+
+ def testIntervalPretty(self):
+ def ae(spec, pretty):
+ self.assertEqual(Interval(spec).pretty(), pretty)
+ ae('2y', 'in 2 years')
+ ae('1y', 'in 1 year')
+ ae('2m', 'in 2 months')
+ ae('1m 30d', 'in 2 months')
+ ae('60d', 'in 2 months')
+ ae('59d', 'in 1 month')
+ ae('1m', 'in 1 month')
+ ae('29d', 'in 1 month')
+ ae('28d', 'in 4 weeks')
+ ae('8d', 'in 1 week')
+ ae('7d', 'in 7 days')
+ ae('1w', 'in 7 days')
+ ae('2d', 'in 2 days')
+ ae('1d', 'tomorrow')
+ ae('02:00:00', 'in 2 hours')
+ ae('01:59:00', 'in 1 3/4 hours')
+ ae('01:45:00', 'in 1 3/4 hours')
+ ae('01:30:00', 'in 1 1/2 hours')
+ ae('01:29:00', 'in 1 1/4 hours')
+ ae('01:00:00', 'in an hour')
+ ae('00:30:00', 'in 1/2 an hour')
+ ae('00:15:00', 'in 1/4 hour')
+ ae('00:02:00', 'in 2 minutes')
+ ae('00:01:00', 'in 1 minute')
+ ae('00:00:30', 'in a moment')
+ ae('-00:00:30', 'just now')
+ ae('-1d', 'yesterday')
+ ae('-1y', '1 year ago')
+ ae('-2y', '2 years ago')
def test_suite():
suite = unittest.TestSuite()