41 lines
934 B
Python
41 lines
934 B
Python
import datetime
|
|
from typing import List
|
|
|
|
|
|
def get_current_term() -> str:
|
|
"""
|
|
Get the current term as formatted in the CSC LDAP (e.g. 's2021').
|
|
"""
|
|
dt = datetime.datetime.now()
|
|
c = 'w'
|
|
if 5 <= dt.month <= 8:
|
|
c = 's'
|
|
elif 9 <= dt.month:
|
|
c = 'f'
|
|
return c + str(dt.year)
|
|
|
|
|
|
def add_term(term: str) -> str:
|
|
"""
|
|
Add one term to the given term and return the string.
|
|
Example: add_term('s2021') -> 'f2021'
|
|
"""
|
|
c = term[0]
|
|
s_year = term[1:]
|
|
if c == 'w':
|
|
return 's' + s_year
|
|
elif c == 's':
|
|
return 'f' + s_year
|
|
year = int(s_year)
|
|
return 'w' + str(year + 1)
|
|
|
|
|
|
def get_max_term(terms: List[str]) -> str:
|
|
"""Get the maximum (latest) term."""
|
|
max_year = max(term[1:] for term in terms)
|
|
if 'f' + max_year in terms:
|
|
return 'f' + max_year
|
|
elif 's' + max_year in terms:
|
|
return 's' + max_year
|
|
return 'w' + max_year
|