Skip to content

Commit 6095771

Browse files
committed
Refactor: Move define declarations from class level to class methods
- solve impl problem
1 parent 1a77963 commit 6095771

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/pendulum/formatting/difference_formatter.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ class DifferenceFormatter:
2626
Handles formatting differences in text.
2727
"""
2828

29-
KEY_FUTURE = ".future"
30-
KEY_PAST = ".past"
31-
KEY_AFTER = ".after"
32-
KEY_BEFORE = ".before"
33-
3429
def __init__(self, locale: str = "en") -> None:
3530
self._locale = Locale.load(locale)
3631

@@ -49,6 +44,11 @@ def format(
4944
:param absolute: Whether it's an absolute difference or not
5045
:param locale: The locale to use
5146
"""
47+
KEY_FUTURE = ".future"
48+
KEY_PAST = ".past"
49+
KEY_AFTER = ".after"
50+
KEY_BEFORE = ".before"
51+
5252
locale = self._locale if locale is None else Locale.load(locale)
5353

5454
if diff.years > 0:
@@ -108,9 +108,9 @@ def format(
108108
key += ".ago"
109109
else:
110110
if is_future:
111-
key += self.KEY_AFTER
111+
key += KEY_AFTER
112112
else:
113-
key += self.KEY_BEFORE
113+
key += KEY_BEFORE
114114

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

133133
if is_future:
134-
key += self.KEY_FUTURE
134+
key += KEY_FUTURE
135135
else:
136-
key += self.KEY_PAST
136+
key += KEY_PAST
137137
else:
138138
# Absolute comparison
139139
# So we have to use the custom locale data
140140

141141
# Checking for special pluralization rules
142142
key = "custom.units_relative"
143143
if is_future:
144-
key += f".{unit}{self.KEY_FUTURE}"
144+
key += f".{unit}{KEY_FUTURE}"
145145
else:
146-
key += f".{unit}{self.KEY_PAST}"
146+
key += f".{unit}{KEY_PAST}"
147147

148148
trans = locale.get(key)
149149
if not trans:
@@ -155,9 +155,9 @@ def format(
155155

156156
key = "custom"
157157
if is_future:
158-
key += self.KEY_AFTER
158+
key += KEY_AFTER
159159
else:
160-
key += self.KEY_BEFORE
160+
key += KEY_BEFORE
161161
return t.cast(str, locale.get(key).format(time))
162162

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

0 commit comments

Comments
 (0)