Skip to content

Commit

Permalink
Refactor: Move define declarations from class level to class methods
Browse files Browse the repository at this point in the history
- solve impl problem
  • Loading branch information
Minku-Koo committed Dec 10, 2024
1 parent 1a77963 commit 6095771
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/pendulum/formatting/difference_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ class DifferenceFormatter:
Handles formatting differences in text.
"""

KEY_FUTURE = ".future"
KEY_PAST = ".past"
KEY_AFTER = ".after"
KEY_BEFORE = ".before"

def __init__(self, locale: str = "en") -> None:
self._locale = Locale.load(locale)

Expand All @@ -49,6 +44,11 @@ def format(
:param absolute: Whether it's an absolute difference or not
:param locale: The locale to use
"""
KEY_FUTURE = ".future"
KEY_PAST = ".past"
KEY_AFTER = ".after"
KEY_BEFORE = ".before"

locale = self._locale if locale is None else Locale.load(locale)

if diff.years > 0:
Expand Down Expand Up @@ -108,9 +108,9 @@ def format(
key += ".ago"
else:
if is_future:
key += self.KEY_AFTER
key += KEY_AFTER
else:
key += self.KEY_BEFORE
key += KEY_BEFORE

return t.cast(str, locale.get(key).format(time))
else:
Expand All @@ -131,19 +131,19 @@ def format(
key = f"translations.relative.{unit}"

if is_future:
key += self.KEY_FUTURE
key += KEY_FUTURE
else:
key += self.KEY_PAST
key += KEY_PAST
else:
# Absolute comparison
# So we have to use the custom locale data

# Checking for special pluralization rules
key = "custom.units_relative"
if is_future:
key += f".{unit}{self.KEY_FUTURE}"
key += f".{unit}{KEY_FUTURE}"
else:
key += f".{unit}{self.KEY_PAST}"
key += f".{unit}{KEY_PAST}"

trans = locale.get(key)
if not trans:
Expand All @@ -155,9 +155,9 @@ def format(

key = "custom"
if is_future:
key += self.KEY_AFTER
key += KEY_AFTER
else:
key += self.KEY_BEFORE
key += KEY_BEFORE
return t.cast(str, locale.get(key).format(time))

key += f".{locale.plural(count)}"
Expand Down

0 comments on commit 6095771

Please sign in to comment.