MCPcopy Create free account
hub / github.com/python-pendulum/pendulum / in_words

Method in_words

src/pendulum/duration.py:241–284  ·  view source on GitHub ↗

Get the current interval in words in the current locale. Ex: 6 jours 23 heures 58 minutes :param locale: The locale to use. Defaults to current locale. :param separator: The separator to use between each unit

(self, locale: str | None = None, separator: str = " ")

Source from the content-addressed store, hash-verified

239 return int(self.total_seconds())
240
241 def in_words(self, locale: str | None = None, separator: str = " ") -> str:
242 """
243 Get the current interval in words in the current locale.
244
245 Ex: 6 jours 23 heures 58 minutes
246
247 :param locale: The locale to use. Defaults to current locale.
248 :param separator: The separator to use between each unit
249 """
250 intervals = [
251 ("year", self.years),
252 ("month", self.months),
253 ("week", self.weeks),
254 ("day", self.remaining_days),
255 ("hour", self.hours),
256 ("minute", self.minutes),
257 ("second", self.remaining_seconds),
258 ]
259
260 if locale is None:
261 locale = pendulum.get_locale()
262
263 loaded_locale = pendulum.locale(locale)
264
265 parts = []
266 for interval in intervals:
267 unit, interval_count = interval
268 if abs(interval_count) > 0:
269 translation = loaded_locale.translation(
270 f"units.{unit}.{loaded_locale.plural(abs(interval_count))}"
271 )
272 parts.append(translation.format(interval_count))
273
274 if not parts:
275 count: int | str = 0
276 if self.microseconds != 0:
277 unit = f"units.second.{loaded_locale.plural(0)}"
278 count = f"{abs(self.microseconds) / 1e6:.2f}"
279 else:
280 unit = f"units.microsecond.{loaded_locale.plural(0)}"
281 translation = loaded_locale.translation(unit)
282 parts.append(translation.format(count))
283
284 return separator.join(parts)
285
286 def _sign(self, value: float) -> int:
287 if value < 0:

Callers 15

__str__Method · 0.95
test_weekFunction · 0.45
test_weeks_and_dayFunction · 0.45
test_allFunction · 0.45
test_in_frenchFunction · 0.45
test_separatorFunction · 0.45
test_subsecondsFunction · 0.45
test_weekFunction · 0.45
test_week_and_dayFunction · 0.45

Calls 3

translationMethod · 0.80
pluralMethod · 0.80
formatMethod · 0.45

Tested by 15

test_weekFunction · 0.36
test_weeks_and_dayFunction · 0.36
test_allFunction · 0.36
test_in_frenchFunction · 0.36
test_separatorFunction · 0.36
test_subsecondsFunction · 0.36
test_weekFunction · 0.36
test_week_and_dayFunction · 0.36
test_allFunction · 0.36