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)