From 7ddc9ececf70998f373236b8fd9f7dd9967accf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Wed, 8 Mar 2023 19:00:59 +0800 Subject: [PATCH] Added the __format_day method to the PeriodDescription utility to simplify the code. --- src/accounting/report/period.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/accounting/report/period.py b/src/accounting/report/period.py index 0165b06..3f027ae 100644 --- a/src/accounting/report/period.py +++ b/src/accounting/report/period.py @@ -340,9 +340,7 @@ class PeriodDescription: :return: The description as a day range. :raise ValueError: The period is a month or year range. """ - start: str = "{year}/{month}/{day}".format( - year=self.__start.year, month=self.__start.month, - day=self.__start.day) + start: str = self.__format_day(self.__start) if self.__start == self.__end: return gettext("in %(period)s", period=start) if self.__start.year == self.__end.year \ @@ -374,6 +372,15 @@ class PeriodDescription: """ return f"{month.year}/{month.month}" + @staticmethod + def __format_day(day: datetime.date) -> str: + """Formats a day. + + :param day: The day. + :return: The formatted day. + """ + return f"{day.year}/{day.month}/{day.day}" + class ThisMonth(Period): """The period of this month."""