next_month / previous_month now support a new arg to give number of month tls-sprint
authorsylvain.thenault@logilab.fr
Tue, 05 May 2009 19:30:29 +0200
branchtls-sprint
changeset 1697 5dae28906769
parent 1696 ee0bea49e0e1
child 1698 1311d961ef72
next_month / previous_month now support a new arg to give number of month
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)