Coverage for /pythoncovmergedfiles/medio/medio/src/jupyter_server/jupyter_server/_tz.py: 69%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""
2Timezone utilities
4Just UTC-awareness right now
5"""
7# Copyright (c) Jupyter Development Team.
8# Distributed under the terms of the Modified BSD License.
9from __future__ import annotations
11from datetime import datetime, timedelta, timezone, tzinfo
13# constant for zero offset
14ZERO = timedelta(0)
17class tzUTC(tzinfo): # noqa: N801
18 """tzinfo object for UTC (zero offset)"""
20 def utcoffset(self, d: datetime | None) -> timedelta:
21 """Compute utcoffset."""
22 return ZERO
24 def dst(self, d: datetime | None) -> timedelta:
25 """Compute dst."""
26 return ZERO
29def utcnow() -> datetime:
30 """Return timezone-aware UTC timestamp"""
31 return datetime.now(timezone.utc)
34def utcfromtimestamp(timestamp: float) -> datetime:
35 return datetime.fromtimestamp(timestamp, timezone.utc)
38UTC = tzUTC() # type:ignore[abstract]
41def isoformat(dt: datetime) -> str:
42 """Return iso-formatted timestamp
44 Like .isoformat(), but uses Z for UTC instead of +00:00
45 """
46 return dt.isoformat().replace("+00:00", "Z")