Show seconds in human form. For example, 60 becomes "1 minute", and 7200 becomes "2 hours". Arguments: prefix (str): can be used to add a preposition to the output (e.g., 'in' will give 'in 1 second', but add nothing to 'now'). now (str): Literal 'now'.
(
secs: int, prefix: str = '', sep: str = '', now: str = 'now',
microseconds: bool = False)
| 348 | |
| 349 | |
| 350 | def humanize_seconds( |
| 351 | secs: int, prefix: str = '', sep: str = '', now: str = 'now', |
| 352 | microseconds: bool = False) -> str: |
| 353 | """Show seconds in human form. |
| 354 | |
| 355 | For example, 60 becomes "1 minute", and 7200 becomes "2 hours". |
| 356 | |
| 357 | Arguments: |
| 358 | prefix (str): can be used to add a preposition to the output |
| 359 | (e.g., 'in' will give 'in 1 second', but add nothing to 'now'). |
| 360 | now (str): Literal 'now'. |
| 361 | microseconds (bool): Include microseconds. |
| 362 | """ |
| 363 | secs = float(format(float(secs), '.2f')) |
| 364 | for unit, divider, formatter in TIME_UNITS: |
| 365 | if secs >= divider: |
| 366 | w = secs / float(divider) |
| 367 | return '{}{}{} {}'.format(prefix, sep, formatter(w), |
| 368 | pluralize(w, unit)) |
| 369 | if microseconds and secs > 0.0: |
| 370 | return '{prefix}{sep}{0:.2f} seconds'.format( |
| 371 | secs, sep=sep, prefix=prefix) |
| 372 | return now |
| 373 | |
| 374 | |
| 375 | def maybe_iso8601(dt: datetime | str | None) -> None | datetime: |