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 = " ")
| 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: |