summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Garaud <damien.garaud@logilab.fr>2013-10-31 09:36:25 +0100
committerDamien Garaud <damien.garaud@logilab.fr>2013-10-31 09:36:25 +0100
commit2a2cb089cbd8186637546838f0e883c5abaf6490 (patch)
treec47427dfa453078011e1232e4e1b8d3bc3e67c4e
parentd4dddabb498eb1b0f677ed3555478cfd12e330bf (diff)
downloadlogilab-common-2a2cb089cbd8186637546838f0e883c5abaf6490.tar.gz
[date] Fixed: wrong incrementation of month in date_range function (closes #186698).
Add a unit test.
-rw-r--r--date.py2
-rw-r--r--test/unittest_date.py7
2 files changed, 8 insertions, 1 deletions
diff --git a/date.py b/date.py
index ae5025e..bd660c0 100644
--- a/date.py
+++ b/date.py
@@ -188,8 +188,8 @@ def date_range(begin, end, incday=None, incmonth=None):
end = todate(end)
if incmonth:
while begin < end:
- begin = next_month(begin, incmonth)
yield begin
+ begin = next_month(begin, incmonth)
else:
incr = get_step(begin, incday or 1)
while begin < end:
diff --git a/test/unittest_date.py b/test/unittest_date.py
index 0aa1de8..ba1522c 100644
--- a/test/unittest_date.py
+++ b/test/unittest_date.py
@@ -138,6 +138,13 @@ class DateTC(TestCase):
date = ticks2datetime(ticks)
self.assertEqual(ustrftime(date, '%Y-%m-%d'), u'1899-12-31')
+ def test_month(self):
+ """enumerate months"""
+ r = list(date_range(self.datecls(2006, 5, 6), self.datecls(2006, 8, 27),
+ incmonth=True))
+ expected = [self.datecls(2006, 5, 6), self.datecls(2006, 6, 1), self.datecls(2006, 7, 1), self.datecls(2006, 8, 1)]
+ self.assertListEqual(expected, r)
+
class MxDateTC(DateTC):
datecls = mxDate