MCPcopy Index your code
hub / github.com/python-pendulum/pendulum / in_words

Method in_words

src/pendulum/interval.py:247–288  ·  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

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

Callers

nothing calls this directly

Calls 4

loadMethod · 0.80
translationMethod · 0.80
pluralMethod · 0.80
formatMethod · 0.45

Tested by

no test coverage detected