This document describes an older version of Celery (2.5). For the latest stable version please go here.

celery.utils.timeutils

celery.utils.timeutils

This module contains various utilities relating to dates and times.

copyright:
  1. 2009 - 2012 by Ask Solem.
license:

BSD, see LICENSE for more details.

exception celery.utils.timeutils.UnknownTimezone

No specification exists for the timezone specified. Consider installing the pytz library to get access to more timezones.

celery.utils.timeutils.delta_resolution(dt, delta)

Round a datetime to the resolution of a 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.timeutils.humanize_seconds(secs, prefix='')

Show seconds in human form, e.g. 60 is “1 minute”, 7200 is “2 hours”.

celery.utils.timeutils.maybe_iso8601(dt)

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

celery.utils.timeutils.maybe_timedelta(delta)

Coerces integer to timedelta if delta is an integer.

celery.utils.timeutils.rate(rate)

Parses rate strings, such as “100/m” or “2/h” and converts them to seconds.

celery.utils.timeutils.remaining(start, ends_in, now=None, relative=False)

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

e.g. “how many seconds left for 30 seconds after start?”

Parameters:
  • start – Start datetime.
  • ends_in – The end delta as a timedelta.
  • relative – If enabled the end time will be calculated using delta_resolution() (i.e. rounded to the resolution of ends_in).
  • now – Function returning the current time and date, defaults to datetime.utcnow().
celery.utils.timeutils.timedelta_seconds(delta)

Convert datetime.timedelta to seconds.

Doesn’t account for negative values.

celery.utils.timeutils.weekday(name)

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

Example:

>>> weekday("sunday"), weekday("sun"), weekday("mon")
(0, 0, 1)

Previous topic

celery.utils.term

Next topic

celery.utils.encoding

This Page