1"""
2Timezone utilities
3
4Just UTC-awareness right now
5"""
6
7# Copyright (c) Jupyter Development Team.
8# Distributed under the terms of the Modified BSD License.
9from __future__ import annotations
10
11from datetime import datetime, timedelta, timezone, tzinfo
12
13# constant for zero offset
14ZERO = timedelta(0)
15
16
17class tzUTC(tzinfo): # noqa: N801
18 """tzinfo object for UTC (zero offset)"""
19
20 def utcoffset(self, d: datetime | None) -> timedelta:
21 """Compute utcoffset."""
22 return ZERO
23
24 def dst(self, d: datetime | None) -> timedelta:
25 """Compute dst."""
26 return ZERO
27
28
29def utcnow() -> datetime:
30 """Return timezone-aware UTC timestamp"""
31 return datetime.now(timezone.utc)
32
33
34def utcfromtimestamp(timestamp: float) -> datetime:
35 return datetime.fromtimestamp(timestamp, timezone.utc)
36
37
38UTC = tzUTC() # type:ignore[abstract]
39
40
41def isoformat(dt: datetime) -> str:
42 """Return iso-formatted timestamp
43
44 Like .isoformat(), but uses Z for UTC instead of +00:00
45 """
46 return dt.isoformat().replace("+00:00", "Z")