summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZiang Song <ziang.song@nrgenergy.com>2015-12-03 21:40:44 (GMT)
committerZiang Song <ziang.song@nrgenergy.com>2015-12-03 21:40:44 (GMT)
commit76aead490da1fc6286ce9db429570b34f5be7c4c (patch)
tree8bed659ea8ad0478953380c5b6fddba1759954f9
parent27d3bca47e4d39bd5038665726fb157577c5abfa (diff)
downloadisodate-76aead490da1fc6286ce9db429570b34f5be7c4c.tar.gz
https://github.com/gweis/isodate/issues/33
-rw-r--r--src/isodate/duration.py5
-rw-r--r--src/isodate/tests/test_duration.py7
2 files changed, 11 insertions, 1 deletions
diff --git a/src/isodate/duration.py b/src/isodate/duration.py
index 5408315..7eeffad 100644
--- a/src/isodate/duration.py
+++ b/src/isodate/duration.py
@@ -121,7 +121,10 @@ class Duration(object):
if self.years:
params.append('%d years' % self.years)
if self.months:
- params.append('%d months' % self.months)
+ fmt = "%d months"
+ if self.months <= 1:
+ fmt = "%d month"
+ params.append(fmt % self.months)
params.append(str(self.tdelta))
return ', '.join(params)
diff --git a/src/isodate/tests/test_duration.py b/src/isodate/tests/test_duration.py
index 0b80a54..5bb8acb 100644
--- a/src/isodate/tests/test_duration.py
+++ b/src/isodate/tests/test_duration.py
@@ -314,6 +314,13 @@ class DurationTest(unittest.TestCase):
self.assertEqual('isodate.duration.Duration(10, 10, 0,'
' years=10, months=10)', repr(dur))
+ dur = Duration(months=0)
+ self.assertEqual('0:00:00', str(dur))
+
+ dur = Duration(months=1)
+ self.assertEqual('1 month, 0:00:00', str(dur))
+
+
def test_hash(self):
'''
Test __hash__ for Duration objects.