2017-05-02 10:00:47 +01:00
|
|
|
from datetime import datetime, timedelta
|
2017-04-26 14:16:47 +01:00
|
|
|
|
|
|
|
|
import pytz
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_financial_year(year):
|
2017-05-02 10:00:47 +01:00
|
|
|
return get_april_fools(year), get_april_fools(year + 1) - timedelta(microseconds=1)
|
2017-04-26 14:16:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_april_fools(year):
|
|
|
|
|
"""
|
|
|
|
|
This function converts the start of the financial year April 1, 00:00 as BST (British Standard Time) to UTC,
|
|
|
|
|
the tzinfo is lastly removed from the datetime becasue the database stores the timestamps without timezone.
|
|
|
|
|
:param year: the year to calculate the April 1, 00:00 BST for
|
|
|
|
|
:return: the datetime of April 1 for the given year, for example 2016 = 2016-03-31 23:00:00
|
|
|
|
|
"""
|
|
|
|
|
return pytz.timezone('Europe/London').localize(datetime(year, 4, 1, 0, 0, 0)).astimezone(pytz.UTC).replace(
|
|
|
|
|
tzinfo=None)
|