Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better way of finding term starts #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions oxford_term_dates/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,30 @@ def term_as_string(year=None, term=None):
def term_start(pdate=None):
if pdate is None:
pdate = date.today()
for i in range(1, len(OFFSET_TERM_STARTS_LIST)):
if OFFSET_TERM_STARTS_LIST[i-1][1] <= pdate and OFFSET_TERM_STARTS_LIST[i][1] > pdate:
break
return OFFSET_TERM_STARTS_LIST[i-1][0]
for year in range(pdate.year-1, pdate.year+2):
for term in (1, 2, 3):
try:
offset_term_start = OFFSET_TERM_STARTS[(year, term)]
except KeyError:
continue

if offset_term_start > pdate:
raise ValueError("We don't have dates going that far back.")

if term == 3:
next_year, next_term = year + 1, 1
else:
next_year, next_term = year, term + 1

try:
next_offset_term_start = OFFSET_TERM_STARTS[(next_year, next_term)]
except KeyError:
# We've run out of info; we're done here
return year, term

if next_offset_term_start > pdate:
return year, term



def ox_to_normal(year, term, week=0, day=0):
Expand Down