[date] Fixed: wrong incrementation of month in date_range function (closes #186698).

Add a unit test.

authorDamien Garaud <damien.garaud@logilab.fr>
changesetb42796404f1b
branchdefault
phasedraft
hiddenyes
parent revision#e9fc9f452231 merge default heads
child revision<not specified>
files modified by this revision
date.py
test/unittest_date.py
# HG changeset patch
# User Damien Garaud <damien.garaud@logilab.fr>
# Date 1383208585 -3600
# Thu Oct 31 09:36:25 2013 +0100
# Node ID b42796404f1b8135289939f9b73f826f199db984
# Parent e9fc9f4522317c21d543a41a4f630d5fb3142e8f
[date] Fixed: wrong incrementation of month in date_range function (closes #186698).

Add a unit test.

diff --git a/date.py b/date.py
@@ -186,12 +186,12 @@
1      assert not (incday and incmonth)
2      begin = todate(begin)
3      end = todate(end)
4      if incmonth:
5          while begin < end:
6 +            yield begin
7              begin = next_month(begin, incmonth)
8 -            yield begin
9      else:
10          incr = get_step(begin, incday or 1)
11          while begin < end:
12             yield begin
13             begin += incr
diff --git a/test/unittest_date.py b/test/unittest_date.py
@@ -136,10 +136,17 @@
14      def test_ticks2datetime_before_1900(self):
15          ticks = -2209075200000
16          date = ticks2datetime(ticks)
17          self.assertEqual(ustrftime(date, '%Y-%m-%d'), u'1899-12-31')
18 
19 +    def test_month(self):
20 +        """enumerate months"""
21 +        r = list(date_range(self.datecls(2006, 5, 6), self.datecls(2006, 8, 27),
22 +                            incmonth=True))
23 +        expected = [self.datecls(2006, 5, 6), self.datecls(2006, 6, 1), self.datecls(2006, 7, 1), self.datecls(2006, 8, 1)]
24 +        self.assertListEqual(expected, r)
25 +
26 
27  class MxDateTC(DateTC):
28      datecls = mxDate
29      datetimecls = mxDateTime
30      timedeltacls = RelativeDateTime