From 2371c2c9a7ed079bfa83f8875c634f83fbe393d0 Mon Sep 17 00:00:00 2001 From: Imdad Ahad Date: Fri, 18 Aug 2017 12:45:05 +0100 Subject: [PATCH] Add helper to get months for a financial year: * No tests have been added as this was taken from the admin where it is already tested thoroughly. * TODO: Move to utils --- app/dao/date_util.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/dao/date_util.py b/app/dao/date_util.py index 5840fb886..8815e94cd 100644 --- a/app/dao/date_util.py +++ b/app/dao/date_util.py @@ -5,6 +5,20 @@ import pytz from app.utils import convert_bst_to_utc +def get_months_for_financial_year(year): + return [ + convert_bst_to_utc(month) for month in ( + get_months_for_year(4, 13, year) + + get_months_for_year(1, 4, year + 1) + ) + if month < datetime.now() + ] + + +def get_months_for_year(start, end, year): + return [datetime(year, month, 1) for month in range(start, end)] + + def get_financial_year(year): return get_april_fools(year), get_april_fools(year + 1) - timedelta(microseconds=1)