Added the __format_day method to the PeriodDescription utility to simplify the code.

This commit is contained in:
依瑪貓 2023-03-08 19:00:59 +08:00
parent 4eebbd9692
commit 7ddc9ececf

View File

@ -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."""