MCPcopy
hub / github.com/zenml-io/zenml / utc_now

Function utc_now

src/zenml/utils/time_utils.py:21–45  ·  view source on GitHub ↗

Get the current time in the UTC timezone. Args: tz_aware: Use this flag to control whether the returned datetime is timezone-aware or timezone-naive. If a datetime is provided, the returned datetime will be timezone-aware if and only if the input date

(tz_aware: Union[bool, datetime] = False)

Source from the content-addressed store, hash-verified

19
20
21def utc_now(tz_aware: Union[bool, datetime] = False) -> datetime:
22 """Get the current time in the UTC timezone.
23
24 Args:
25 tz_aware: Use this flag to control whether the returned datetime is
26 timezone-aware or timezone-naive. If a datetime is provided, the
27 returned datetime will be timezone-aware if and only if the input
28 datetime is also timezone-aware.
29
30 Returns:
31 The current UTC time. If tz_aware is a datetime, the returned datetime
32 will be timezone-aware only if the input datetime is also timezone-aware.
33 If tz_aware is a boolean, the returned datetime will be timezone-aware
34 if True, and timezone-naive if False.
35 """
36 now = datetime.now(timezone.utc)
37 if (
38 isinstance(tz_aware, bool)
39 and tz_aware is False
40 or isinstance(tz_aware, datetime)
41 and tz_aware.tzinfo is None
42 ):
43 return now.replace(tzinfo=None)
44
45 return now
46
47
48def utc_now_tz_aware() -> datetime:

Callers 15

format_name_templateFunction · 0.90
to_response_modelMethod · 0.90
has_expiredMethod · 0.90
_fetch_tokenMethod · 0.90
_get_tokenMethod · 0.90
publish_failed_step_runFunction · 0.90
publish_stopped_step_runFunction · 0.90
_finalize_shutdownMethod · 0.90

Calls 1

nowMethod · 0.45