summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--app/views/consts.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/app/views/consts.py b/app/views/consts.py
index 4b5ea68..c8d9d99 100644
--- a/app/views/consts.py
+++ b/app/views/consts.py
@@ -13,6 +13,14 @@ from functools import partial
mod = Blueprint('consts', __name__)
assert_authorisation = partial(assert_authorisation, ConstExpense.get)
+def one_year(d):
+ """Returns the date d', such that [d, d'] spans exactly one year.
+ In effect, this is d + 11 months (NB: not 12!)"""
+ if d.month == 1:
+ return d.replace(month = 12)
+ else:
+ return d.replace(month = (d.month + 11) % 12, year = d.year + 1)
+
#
# Form
#
@@ -23,7 +31,7 @@ class ConstForm(F.Form):
end = F.DateField(u'Ende', F.req,
format='%m.%Y',
- default=lambda: today().replace(year = today().year + 1),
+ default=lambda: one_year(today()),
description=u'(einschließlich)')
months = F.IntegerField(u'Zahlungsrythmus', F.req,
@@ -155,7 +163,7 @@ def add_from(other):
# replace some fields to be more meaningful
start = max(form.end.data, today())
form.start.data = start
- form.end.data = start.replace(year = start.year + 1)
+ form.end.data = one_year(start)
if not other.next: form.prev.data = other
return { 'form': form }