Revised the styles of the f-strings in the Period utility.

This commit is contained in:
依瑪貓 2023-03-08 18:37:11 +08:00
parent 9b273115a0
commit f438f97571

View File

@ -244,7 +244,7 @@ class Period:
:param date: The date. :param date: The date.
:return: The formatted date. :return: The formatted date.
""" """
return F"{date.year}/{date.month}/{date.day}" return f"{date.year}/{date.month}/{date.day}"
@staticmethod @staticmethod
def __format_month(month: datetime.date) -> str: def __format_month(month: datetime.date) -> str:
@ -253,7 +253,7 @@ class Period:
:param month: The month. :param month: The month.
:return: The formatted month. :return: The formatted month.
""" """
return F"{month.year}/{month.month}" return f"{month.year}/{month.month}"
def __get_year_desc(self) -> str: def __get_year_desc(self) -> str:
"""Returns the description as a year range. """Returns the description as a year range.
@ -278,14 +278,14 @@ class Period:
""" """
if self.start.day != 1 or self.end != _month_end(self.end): if self.start.day != 1 or self.end != _month_end(self.end):
raise ValueError raise ValueError
start: str = F"{self.start.year}/{self.start.month}" start: str = f"{self.start.year}/{self.start.month}"
if self.start.year == self.end.year \ if self.start.year == self.end.year \
and self.start.month == self.end.month: and self.start.month == self.end.month:
return gettext("in %(period)s", period=start) return gettext("in %(period)s", period=start)
if self.start.year == self.end.year: if self.start.year == self.end.year:
end_month: str = str(self.end.month) end_month: str = str(self.end.month)
return gettext("in %(start)s-%(end)s", start=start, end=end_month) return gettext("in %(start)s-%(end)s", start=start, end=end_month)
end: str = F"{self.end.year}/{self.end.month}" end: str = f"{self.end.year}/{self.end.month}"
return gettext("in %(start)s-%(end)s", start=start, end=end) return gettext("in %(start)s-%(end)s", start=start, end=end)
def __get_day_desc(self) -> str: def __get_day_desc(self) -> str:
@ -294,7 +294,7 @@ class Period:
:return: The description as a day range. :return: The description as a day range.
:raise ValueError: The period is a month or year range. :raise ValueError: The period is a month or year range.
""" """
start: str = F"{self.start.year}/{self.start.month}/{self.start.day}" start: str = f"{self.start.year}/{self.start.month}/{self.start.day}"
if self.start == self.end: if self.start == self.end:
return gettext("in %(period)s", period=start) return gettext("in %(period)s", period=start)
if self.start.year == self.end.year \ if self.start.year == self.end.year \
@ -302,10 +302,10 @@ class Period:
end_day: str = str(self.end.day) end_day: str = str(self.end.day)
return gettext("in %(start)s-%(end)s", start=start, end=end_day) return gettext("in %(start)s-%(end)s", start=start, end=end_day)
if self.start.year == self.end.year: if self.start.year == self.end.year:
end_month_day: str = F"{self.end.month}/{self.end.day}" end_month_day: str = f"{self.end.month}/{self.end.day}"
return gettext("in %(start)s-%(end)s", return gettext("in %(start)s-%(end)s",
start=start, end=end_month_day) start=start, end=end_month_day)
end: str = F"{self.end.year}/{self.end.month}/{self.end.day}" end: str = f"{self.end.year}/{self.end.month}/{self.end.day}"
return gettext("in %(start)s-%(end)s", start=start, end=end) return gettext("in %(start)s-%(end)s", start=start, end=end)
def is_year(self, year: int) -> bool: def is_year(self, year: int) -> bool: