git » el » commit e5def32

Fix broken timedelta(months = x) usage

author Alberto Bertogli
2010-06-24 23:19:36 UTC
committer Alberto Bertogli
2010-06-24 23:19:36 UTC
parent 155cf8c8287b0ef72fc90a444feb4c919f981abd

Fix broken timedelta(months = x) usage

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>

el +5 -7

diff --git a/el b/el
index c3e29ed..3f23fb6 100755
--- a/el
+++ b/el
@@ -129,10 +129,6 @@ def parse_when(w):
 				td = datetime.timedelta(days = incr)
 			if w[-1] == 'w':
 				td = datetime.timedelta(weeks = incr)
-			if w[-1] == 'm':
-				td = datetime.timedelta(months = incr)
-			if w[-1] == 'y':
-				td = datetime.timedelta(years = incr)
 		else:
 			incr = int(w[1:])
 			td = datetime.timedelta(days = incr)
@@ -142,9 +138,11 @@ def parse_when(w):
 		day = int(w)
 		if day <= today.day:
 			# the day of the next month
-			d = datetime.date(today.year, today.month, day)
-			d += datetime.timedelta(months = 1)
-			return d
+			next_month = (today.month + 1) % 12
+			year = today.year
+			if next_month < today.month:
+				year += 1
+			return datetime.date(year, next_month, day)
 		else:
 			# the day of this month
 			return datetime.date(today.year, today.month, day)