MCPcopy
hub / github.com/celery/celery / maybe_make_aware

Function maybe_make_aware

celery/utils/time.py:377–386  ·  view source on GitHub ↗

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

(dt: datetime, tz: tzinfo | None = None,
                     naive_as_utc: bool = True)

Source from the content-addressed store, hash-verified

375
376
377def maybe_make_aware(dt: datetime, tz: tzinfo | None = None,
378 naive_as_utc: bool = True) -> datetime:
379 """Convert dt to aware datetime, do nothing if dt is already aware."""
380 if is_naive(dt):
381 if naive_as_utc:
382 dt = to_utc(dt)
383 return localize(
384 dt, timezone.utc if tz is None else timezone.tz_or_local(tz),
385 )
386 return dt
387
388
389class ffwd:

Callers 6

test_maybe_make_awareMethod · 0.90
__init__Method · 0.90
send_taskMethod · 0.90
as_task_v2Method · 0.90
maybe_make_awareMethod · 0.85
_whenMethod · 0.85

Calls 4

is_naiveFunction · 0.85
to_utcFunction · 0.85
localizeFunction · 0.85
tz_or_localMethod · 0.80

Tested by 1

test_maybe_make_awareMethod · 0.72