From 342d966f4b3d93cb195a5ae6640bf569b9f09887 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Mon, 10 Oct 2022 11:47:45 +0000 Subject: [PATCH] WIP: Updates for the Gregorian calendar module --- calsocial/calendar_system/gregorian.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/calsocial/calendar_system/gregorian.py b/calsocial/calendar_system/gregorian.py index 807e7a7..e9712b4 100644 --- a/calsocial/calendar_system/gregorian.py +++ b/calsocial/calendar_system/gregorian.py @@ -105,6 +105,13 @@ class GregorianCalendar(CalendarSystem): return self.timestamp.replace(year=self.timestamp.year - 1).year + @property + def current_month_first(self): + """Return the timestamp for the first day of the current month + """ + + return self.timestamp.replace(day=1) + @property def prev_month(self): """Returns the timestamp of the same day in the previous month @@ -113,19 +120,14 @@ class GregorianCalendar(CalendarSystem): if self.timestamp.month == 1: return self.prev_year.replace(month=12) - return self.timestamp.replace(month=self.timestamp.month - 1) + return self.current_month_first - timedelta(days=1) @property def prev_month_name(self): """The name of the previous month """ - if self.timestamp.month == 1: - timestamp = self.prev_year.replace(month=12) - else: - timestamp = self.timestamp.replace(month=self.timestamp.month - 1) - - return self.month_names[timestamp.month - 1] + return self.month_names[self.prev_month.month] @property def next_month(self):