This document describes the current stable version of Celery (4.2). For development docs, go here.


Utilities related to dates, times, intervals, and timezones.

class celery.utils.time.LocalTimezone[source]

Local time implementation.


Used only when the enable_utc setting is disabled.


datetime -> DST offset in minutes east of UTC.


datetime -> string name of time zone.


datetime -> minutes east of UTC (negative for west of UTC).


Convert integer to timedelta, if argument is an integer.

celery.utils.time.delta_resolution(dt, delta)[source]

Round a datetime to the resolution of timedelta.

If the timedelta is in days, the datetime will be rounded to the nearest days, if the timedelta is in hours the datetime will be rounded to the nearest hour, and so on until seconds, which will just return the original datetime.

celery.utils.time.remaining(start, ends_in, now=None, relative=False)[source]

Calculate the remaining time for a start date and a timedelta.

For example, “how many seconds left for 30 seconds after start?”

  • start (datetime) – Starting date.
  • ends_in (timedelta) – The end delta.
  • relative (bool) – If enabled the end time will be calculated using delta_resolution() (i.e., rounded to the resolution of ends_in).
  • now (Callable) – Function returning the current time and date. Defaults to datetime.utcnow().

Remaining time.

Return type:



Convert rate string (“100/m”, “2/h” or “0.5/s”) to seconds.


Return the position of a weekday: 0 - 7, where 0 is Sunday.


>>> weekday('sunday'), weekday('sun'), weekday('mon')
(0, 0, 1)
celery.utils.time.humanize_seconds(secs, prefix=u'', sep=u'', now=u'now', microseconds=False)[source]

Show seconds in human form.

For example, 60 becomes “1 minute”, and 7200 becomes “2 hours”.

  • 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’.
  • microseconds (bool) – Include microseconds.

Either datetime | str -> datetime or None -> None.


Return True if datetime is naive.

celery.utils.time.make_aware(dt, tz)[source]

Set timezone for a datetime object.

celery.utils.time.localize(dt, tz)[source]

Convert aware datetime to another timezone.


Convert naive datetime to UTC.

celery.utils.time.maybe_make_aware(dt, tz=None)[source]

Convert dt to aware datetime, do nothing if dt is already aware.

class celery.utils.time.ffwd(year=None, month=None, weeks=0, weekday=None, day=None, hour=None, minute=None, second=None, microsecond=None, **kwargs)[source]

Version of dateutil.relativedelta that only supports addition.

celery.utils.time.utcoffset(time=<module 'time' (built-in)>, localtime=<built-in function localtime>)[source]

Return the current offset to UTC in hours.

celery.utils.time.adjust_timestamp(ts, offset, here=<function utcoffset>)[source]

Adjust timestamp based on provided utcoffset.

celery.utils.time.get_exponential_backoff_interval(factor, retries, maximum, full_jitter=False)[source]

Calculate the exponential backoff wait time.