diff options
author | Nicolas Chauvat <nicolas.chauvat@logilab.fr> | 2006-08-15 14:05:19 +0200 |
---|---|---|
committer | Nicolas Chauvat <nicolas.chauvat@logilab.fr> | 2006-08-15 14:05:19 +0200 |
commit | 4d59831d47ba0298059feb1a84d6b07fdceefaba (patch) | |
tree | ec4508f4bdae9661fbc28c99b798d702dc95ead5 | |
parent | 09d1ca2a469a985e450ba3f2ce98854ff99f1c07 (diff) | |
download | logilab-common-4d59831d47ba0298059feb1a84d6b07fdceefaba.tar.gz |
define common.date.endOfMonth to make it easier to count months
-rw-r--r-- | date.py | 12 | ||||
-rw-r--r-- | test/unittest_date.py | 8 |
2 files changed, 7 insertions, 13 deletions
@@ -16,26 +16,22 @@ """date manipulation helper functions""" +from mx.DateTime import RelativeDateTime + +endOfMonth = RelativeDateTime(months=1,day=-1) def date_range(begin, end, step=1): """ enumerate dates between begin and end dates. step can either be oneDay, oneHour, oneMinute, oneSecond, oneWeek - use RelativeDateTime(months=1,day=-1) to enumerate months + use endOfMonth to enumerate months """ date = begin while date < end : yield date date += step -# def enum_months(begin, end, day=1): -# klass = type(begin) -# date = begin -# while date < end: -# yield date -# date = RelativeDateTime(months=+1) - FRENCH_FIXED_HOLIDAYS = { 'jour_an' : '%s-01-01', 'fete_travail' : '%s-05-01', diff --git a/test/unittest_date.py b/test/unittest_date.py index 811b376..55c03d6 100644 --- a/test/unittest_date.py +++ b/test/unittest_date.py @@ -3,7 +3,7 @@ Unittests for date helpers """ from logilab.common.testlib import TestCase, unittest_main -from logilab.common.date import date_range +from logilab.common.date import date_range, endOfMonth from mx.DateTime import Date, RelativeDate @@ -20,12 +20,10 @@ class DateTC(TestCase): def test_month(self): """enumerate months""" - r = list(date_range(Date(2000,1,2), Date(2000,4,4), - RelativeDate(months=1,day=-1))) + r = list(date_range(Date(2000,1,2), Date(2000,4,4), endOfMonth)) expected = [Date(2000,1,2), Date(2000,2,29), Date(2000,3,31)] self.assertListEquals(r, expected) - r = list(date_range(Date(2000,11,30), Date(2001,2,3), - RelativeDate(months=1,day=-1))) + r = list(date_range(Date(2000,11,30), Date(2001,2,3), endOfMonth)) expected = [Date(2000,11,30), Date(2000,12,31), Date(2001,1,31)] self.assertListEquals(r, expected) |