MCPcopy Create free account
hub / github.com/celery/celery / humanize_seconds

Function humanize_seconds

celery/utils/time.py:350–372  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

348
349
350def 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
375def maybe_iso8601(dt: datetime | str | None) -> None | datetime:

Callers 12

test_humanize_secondsFunction · 0.90
on_errorMethod · 0.90
startup_infoMethod · 0.90
_error_handlerMethod · 0.90
_error_handlerMethod · 0.90
on_connection_errorMethod · 0.90
_error_handlerFunction · 0.90
human_secondsMethod · 0.85
_is_due_failedMethod · 0.85
startMethod · 0.85
on_errorMethod · 0.85

Calls 2

pluralizeFunction · 0.85
formatMethod · 0.45

Tested by 2

test_humanize_secondsFunction · 0.72