Add utility functions to parse/render dates for termtime and booker
In general TermTime and Booker uses different timezones for dates and time. Add some utility functions to guard against foot guns and makes it obvious when code is parsing date/time in a dangerous manner.
-
booker_format_datetime(dt)
takes adatetime.datetime
object which must have a timezone and renders it as an ISO 8601 "zulu" string (i.e. 2001-02-03T04:05Z) -
booker_parse_datetime(s)
performs the reverse ofbooker_format_datetime
and returns adatetime.datetime
with UTC timezone -
termtime_format_datetime(dt)
takes adatetime.datetime
object which must have a timezone and returns a string suitable for passing to TermTime which formats the datetime in local UK time -
termtime_parse_datetime(s)
takes a datetime string as returned by TermTime in local UK time and returns adatetime.datetime
with UTC timezone
We may need to add some special-case formatting/parsing as required. (E.g. termtime_format_datetime
which returns just the date part, termtime_parse_date
which parses a single date and sets the time to, e.g., midday or termtime_format_duration
which formats a datetime.timedelta
for TermTime.)
This is motivated by two factors:
- We want to make sure to use timezone-aware datetime objects internally for comparisons to avoid errors in BST
- We want to make is obvious when code is not using one of the utility functions and so that date parsing should be carefully examined.
Convert existing date formatting/parsing in the code to use the utility functions.
Edited by Dr Rich Wareham