celery.utils.time¶
Utilities related to dates, times, intervals, and timezones.
- class celery.utils.time.LocalTimezone[源代码]¶
Local time implementation. Provided in _Zone to the app when enable_utc is disabled. Otherwise, _Zone provides a UTC ZoneInfo instance as the timezone implementation for the application.
备注
Used only when the
enable_utcsetting is disabled.
- celery.utils.time.adjust_timestamp(ts: float, offset: int, here: ~typing.Callable[[...], float] = <function utcoffset>) float[源代码]¶
Adjust timestamp based on provided utcoffset.
- celery.utils.time.delta_resolution(dt: datetime, delta: timedelta) datetime[源代码]¶
Round a
datetimeto the resolution of timedelta.If the
timedeltais in days, thedatetimewill be rounded to the nearest days, if thetimedeltais in hours thedatetimewill be rounded to the nearest hour, and so on until seconds, which will just return the originaldatetime.
- class celery.utils.time.ffwd(year=None, month=None, weeks=0, weekday=None, day=None, hour=None, minute=None, second=None, microsecond=None, **kwargs: Any)[源代码]¶
Version of
dateutil.relativedeltathat only supports addition.
- celery.utils.time.get_exponential_backoff_interval(factor: int, retries: int, maximum: int, full_jitter: bool = False) int[源代码]¶
Calculate the exponential backoff wait time.
- celery.utils.time.humanize_seconds(secs: int, prefix: str = '', sep: str = '', now: str = 'now', microseconds: bool = False) str[源代码]¶
Show seconds in human form.
For example, 60 becomes "1 minute", and 7200 becomes "2 hours".
- celery.utils.time.is_naive(dt: datetime) bool[源代码]¶
Return True if
datetimeis naive, meaning it doesn't have timezone info set.
- celery.utils.time.localize(dt: datetime, tz: tzinfo) datetime[源代码]¶
Convert aware
datetimeto another timezone.Using a ZoneInfo timezone will give the most flexibility in terms of ambiguous DST handling.
- celery.utils.time.make_aware(dt: datetime, tz: tzinfo) datetime[源代码]¶
Set timezone for a
datetimeobject.
- celery.utils.time.maybe_iso8601(dt: datetime | str | None) None | datetime[源代码]¶
Either
datetime | str -> datetimeorNone -> None.
- celery.utils.time.maybe_make_aware(dt: datetime, tz: tzinfo | None = None, naive_as_utc: bool = True) datetime[源代码]¶
Convert dt to aware datetime, do nothing if dt is already aware.
- celery.utils.time.maybe_timedelta(delta: int) timedelta[源代码]¶
Convert integer to timedelta, if argument is an integer.
- celery.utils.time.rate(r: str) float[源代码]¶
Convert rate string ("100/m", "2/h" or "0.5/s") to seconds.
- celery.utils.time.remaining(start: datetime, ends_in: timedelta, now: Callable | None = None, relative: bool = False) timedelta[源代码]¶
Calculate the real 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.now(timezone.utc)().
- 返回:
Remaining time.
- 返回类型: