Skip to content

Commit

Permalink
Replace dateutil.tz with ZoneInfo and tzlocal.
Browse files Browse the repository at this point in the history
  • Loading branch information
junhaoliao committed Apr 20, 2024
1 parent 3d69466 commit 0dfdd1a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ readme = "README.md"
requires-python = ">=3.6"
dependencies = [
"clp-ffi-py >= 0.0.9",
"python-dateutil >= 2.7.0",
"typing-extensions >= 3.7.4",
"tzlocal >= 5.2",
"zstandard >= 0.18.0",
]
classifiers = [
Expand Down
10 changes: 3 additions & 7 deletions src/clp_logging/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from types import FrameType
from typing import Callable, ClassVar, Dict, IO, Optional, Tuple, Union

import dateutil.tz
import tzlocal
from clp_ffi_py.ir import FourByteEncoder
from zstandard import FLUSH_FRAME, ZstdCompressionWriter, ZstdCompressor

Expand Down Expand Up @@ -59,12 +59,8 @@ def _init_timeinfo(fmt: Optional[str], tz: Optional[str]) -> Tuple[str, str]:
if not fmt:
fmt = "yyyy-MM-d H:m:s.A"
if not tz:
tzf: Optional[tzinfo] = dateutil.tz.gettz()
if tzf:
tzp: Path = Path.resolve(Path(tzf._filename)) # type: ignore
tz = "/".join([tzp.parent.name, tzp.name])
else:
tz = "UTC"
tz = tzlocal.get_localzone_name()

return fmt, tz


Expand Down
4 changes: 2 additions & 2 deletions src/clp_logging/readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from sys import stderr
from types import TracebackType
from typing import IO, Iterator, List, Match, Optional, Tuple, Type, Union
from zoneinfo import ZoneInfo

import dateutil.tz
from clp_ffi_py.ir import FourByteEncoder
from zstandard import ZstdDecompressionReader, ZstdDecompressor

Expand Down Expand Up @@ -186,7 +186,7 @@ def read_preamble(self) -> int:
# We do not use the timestamp pattern from the preamble as it may
# be from other languages and therefore incompatible.
# self.timestamp_format = self.metadata[METADATA_TIMESTAMP_PATTERN_KEY]
self.timezone = dateutil.tz.gettz(self.metadata[METADATA_TZ_ID_KEY])
self.timezone = ZoneInfo(self.metadata[METADATA_TZ_ID_KEY])
return self.pos

@abstractmethod
Expand Down

0 comments on commit 0dfdd1a

Please sign in to comment.