diff options
author | Matthew Lemon <matt@matthewlemon.com> | 2021-05-16 20:49:47 +0100 |
---|---|---|
committer | Matthew Lemon <matt@matthewlemon.com> | 2021-05-16 20:49:47 +0100 |
commit | e3f26229d0f69ddb93b866e184626337c30778c2 (patch) | |
tree | f717215435d45d6bfb5f80bc9db877cb9ed0b90f | |
parent | a3025ff72dc89a3a26dab359da8f41769bab3b97 (diff) |
changed api for month
-rw-r--r-- | datamaps/core/temporal.py | 17 | ||||
-rw-r--r-- | datamaps/plugins/dft/master.py | 4 | ||||
-rw-r--r-- | datamaps/tests/test_api.py | 14 |
3 files changed, 20 insertions, 15 deletions
diff --git a/datamaps/core/temporal.py b/datamaps/core/temporal.py index 23d4b23..24a0d70 100644 --- a/datamaps/core/temporal.py +++ b/datamaps/core/temporal.py @@ -22,22 +22,22 @@ class Month: } def __init__(self, month: int, year: int): - self._month = month + self._month_int = month self.year = year @property def start_date(self): - return datetime.date(self.year, self._month, 1) + return datetime.date(self.year, self._month_int, 1) @property def end_date(self): - if self._month == 2 and calendar.isleap(self.year): - return datetime.date(self.year, self._month, Month._end_ints[self._month] + 1) + if self._month_int == 2 and calendar.isleap(self.year): + return datetime.date(self.year, self._month_int, Month._end_ints[self._month_int] + 1) else: - return datetime.date(self.year, self._month, Month._end_ints[self._month]) + return datetime.date(self.year, self._month_int, Month._end_ints[self._month_int]) @property - def month(self): + def name(self): return [ "January", "February", @@ -51,7 +51,10 @@ class Month: "October", "November", "December", - ][self._month - 1] + ][self._month_int - 1] + + def __repr__(self): + return f"Month({self.name})" class FinancialYear: diff --git a/datamaps/plugins/dft/master.py b/datamaps/plugins/dft/master.py index 04dfc19..ac81bd9 100644 --- a/datamaps/plugins/dft/master.py +++ b/datamaps/plugins/dft/master.py @@ -217,9 +217,9 @@ class Master: 12: "December", } return [ - m.month + m for m in self.quarter.months - if m.month == months[self._declared_month] + if m.name == months[self._declared_month] ][0] @property diff --git a/datamaps/tests/test_api.py b/datamaps/tests/test_api.py index de9e5ed..e3f3515 100644 --- a/datamaps/tests/test_api.py +++ b/datamaps/tests/test_api.py @@ -22,10 +22,11 @@ def test_get_project_data_using_month(master): assert ( m["Chutney Bridge.xlsm"]["Project/Programme Name"] == "Chutney Bridge Ltd" ) - assert m.month == "July" - assert m2.month == "August" - assert m3.month == "September" - assert m4.month == "October" + assert isinstance(m.month, Month) + assert m.month.name == "July" + assert m2.month.name == "August" + assert m3.month.name == "September" + assert m4.month.name == "October" assert m.quarter.quarter == 2 assert m2.quarter.quarter == 2 assert m3.quarter.quarter == 2 @@ -39,6 +40,7 @@ def test_get_project_data_using_month(master): def test_quarter_objects_have_months(): q = Quarter(1, 2021) q2 = Quarter(4, 2021) + assert isinstance(q.months[0], Month) assert q.months[0].start_date == datetime.date(2021, 4, 1) assert q.months[1].start_date == datetime.date(2021, 5, 1) assert q.months[2].start_date == datetime.date(2021, 6, 1) @@ -53,9 +55,9 @@ def test_quarter_objects_have_months(): def test_month(): m1 = Month(1, 2021) - assert m1.month == "January" + assert m1.name == "January" m2 = Month(9, 2021) - assert m2.month == "September" + assert m2.name == "September" assert m2.start_date == datetime.date(2021, 9, 1) assert m2.end_date == datetime.date(2021, 9, 30) # test leap year |