From 0d7bd1e23e87a0deb2a26f26809942a2a3b7b1ea Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Thu, 11 Apr 2013 12:47:49 +0200 Subject: [PATCH] Forgotten new utils file --- stages/utils.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 stages/utils.py diff --git a/stages/utils.py b/stages/utils.py new file mode 100644 index 0000000..6b5cdb3 --- /dev/null +++ b/stages/utils.py @@ -0,0 +1,18 @@ +# -*- encoding: utf-8 -*- +from __future__ import unicode_literals + + +def school_year(date, as_tuple=False): + """ + Return the school year of 'date'. Example: + * as_tuple = False: "2013 — 2014" + * as_tuple = True: [2013, 2014] + """ + if date.month < 8: + start_year = date.year - 1 + else: + start_year = date.year + if as_tuple: + return (start_year, start_year + 1) + else: + return "%d — %d" % (start_year, start_year + 1)