# HG changeset patch # User sylvain.thenault@logilab.fr # Date 1241544629 -7200 # Node ID 5dae28906769237f62595633816af7bfb0355014 # Parent ee0bea49e0e1a1bbc319ab405875bc18959d9408 next_month / previous_month now support a new arg to give number of month diff -r ee0bea49e0e1 -r 5dae28906769 utils.py --- a/utils.py Tue May 05 19:29:59 2009 +0200 +++ b/utils.py Tue May 05 19:30:29 2009 +0200 @@ -37,15 +37,22 @@ return somedate ONEDAY = timedelta(days=1) +ONEWEEK = timedelta(days=7) def days_in_month(date_): return monthrange(date_.year, date_.month)[1] -def previous_month(date_): - return first_day(date_) - ONEDAY +def previous_month(date_, nbmonth=1): + while nbmonth: + date_ = first_day(date_) - ONEDAY + nbmonth -= 1 + return date_ -def next_month(date_): - return last_day(date_) + ONEDAY +def next_month(date_, nbmonth=1): + while nbmonth: + date_ = last_day(date_) + ONEDAY + nbmonth -= 1 + return date_ def first_day(date_): return date(date_.year, date_.month, 1)