Forgotten new utils file
This commit is contained in:
parent
a139570222
commit
0d7bd1e23e
1 changed files with 18 additions and 0 deletions
18
stages/utils.py
Normal file
18
stages/utils.py
Normal file
|
|
@ -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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue