aboutsummaryrefslogtreecommitdiffstats
path: root/datamaps/core/temporal.py
diff options
context:
space:
mode:
authorMatthew Lemon <matt@matthewlemon.com>2021-05-18 20:26:07 +0100
committerMatthew Lemon <matt@matthewlemon.com>2021-05-18 20:26:07 +0100
commit0f21c97f06bccd2260931e7543a24dc618f355b4 (patch)
tree61ab91a2c9665c2e67b7581652dd2939109266c7 /datamaps/core/temporal.py
parent62617d6ef952c24e134b4bc403263ed990a42ec8 (diff)
fixed test related to getting the correct year from a Month()
Diffstat (limited to 'datamaps/core/temporal.py')
-rw-r--r--datamaps/core/temporal.py45
1 files changed, 24 insertions, 21 deletions
diff --git a/datamaps/core/temporal.py b/datamaps/core/temporal.py
index f97edfa..a927b23 100644
--- a/datamaps/core/temporal.py
+++ b/datamaps/core/temporal.py
@@ -1,6 +1,22 @@
import calendar
import datetime
import itertools
+from typing import List
+
+MONTHS = [
+ "January",
+ "February",
+ "March",
+ "April",
+ "May",
+ "June",
+ "July",
+ "August",
+ "September",
+ "October",
+ "November",
+ "December",
+]
class Month:
@@ -22,40 +38,27 @@ class Month:
}
def __init__(self, month: int, year: int):
- self._month_int = month
+ self.month_int = month
self.year = year
@property
def start_date(self):
- return datetime.date(self.year, self._month_int, 1)
+ return datetime.date(self.year, self.month_int, 1)
@property
def end_date(self):
- if self._month_int == 2 and calendar.isleap(self.year):
+ 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
+ self.year, self.month_int, Month._end_ints[self.month_int] + 1
)
else:
return datetime.date(
- self.year, self._month_int, Month._end_ints[self._month_int]
+ self.year, self.month_int, Month._end_ints[self.month_int]
)
@property
def name(self):
- return [
- "January",
- "February",
- "March",
- "April",
- "May",
- "June",
- "July",
- "August",
- "September",
- "October",
- "November",
- "December",
- ][self._month_int - 1]
+ return MONTHS[self.month_int - 1]
def __repr__(self):
return f"Month({self.name})"
@@ -86,7 +89,7 @@ class FinancialYear:
self.end_date = self.q4.end_date
@property
- def q1(self) -> datetime.date:
+ def q1(self):
"""Quarter 1 as a :py:class:`datetime.date` object"""
return self._q1
@@ -156,7 +159,7 @@ class Quarter:
self.start_date = self._start_date(self.quarter, self.year)
self.end_date = self._end_date(self.quarter, self.year)
- self.months = []
+ self.months: List[Month] = []
self._populate_months()
def _populate_months(self):