MCPcopy
hub / github.com/celery/celery / remaining

Function remaining

celery/utils/time.py:214–250  ·  view source on GitHub ↗

Calculate the real remaining time for a start date and a timedelta. For example, "how many seconds left for 30 seconds after start?" Arguments: start (~datetime.datetime): Starting date. ends_in (~datetime.timedelta): The end delta. relative (bool): If enabled the e

(
        start: datetime, ends_in: timedelta, now: datetime | None = None,
        relative: bool = False)

Source from the content-addressed store, hash-verified

212
213
214def remaining(
215 start: datetime, ends_in: timedelta, now: datetime | None = None,
216 relative: bool = False) -> timedelta:
217 """Calculate the real remaining time for a start date and a timedelta.
218
219 For example, "how many seconds left for 30 seconds after start?"
220
221 Arguments:
222 start (~datetime.datetime): Starting date.
223 ends_in (~datetime.timedelta): The end delta.
224 relative (bool): If enabled the end time will be calculated
225 using :func:`delta_resolution` (i.e., rounded to the
226 resolution of `ends_in`).
227 now (~datetime.datetime): Current time and date.
228 Defaults to :func:`datetime.now(timezone.utc)`.
229
230 Returns:
231 ~datetime.timedelta: Remaining time.
232 """
233 now = now or datetime.now(datetime_timezone.utc)
234 end_date = start + ends_in
235 if relative:
236 end_date = delta_resolution(end_date, ends_in).replace(microsecond=0)
237
238 # Using UTC to calculate real time difference.
239 # Python by default uses wall time in arithmetic between datetimes with
240 # equal non-UTC timezones.
241 now_utc = now.astimezone(timezone.utc)
242 end_date_utc = end_date.astimezone(timezone.utc)
243 ret = end_date_utc - now_utc
244 if C_REMDEBUG: # pragma: no cover
245 print(
246 'rem: NOW:{!r} NOW_UTC:{!r} START:{!r} ENDS_IN:{!r} '
247 'END_DATE:{} END_DATE_UTC:{!r} REM:{}'.format(
248 now, now_utc, start, ends_in, end_date, end_date_utc, ret)
249 )
250 return ret
251
252
253def rate(r: str) -> float:

Callers 3

test_remainingFunction · 0.90
remaining_estimateMethod · 0.85
remaining_estimateMethod · 0.85

Calls 4

delta_resolutionFunction · 0.85
nowMethod · 0.45
replaceMethod · 0.45
formatMethod · 0.45

Tested by 1

test_remainingFunction · 0.72