Skip to content

Commit

Permalink
rm _zoneinfo func
Browse files Browse the repository at this point in the history
  • Loading branch information
FBruzzesi committed Sep 15, 2024
1 parent 58e85fc commit 6fd0603
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
10 changes: 1 addition & 9 deletions dirty_equals/_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,6 @@ def approx_equals(self, other: datetime, delta: timedelta) -> bool:
return True


def _zoneinfo(tz: str) -> ZoneInfo:
"""
Instantiate a `ZoneInfo` object from a string, falling back to `pytz.timezone` when `ZoneInfo` is not available
(most likely on Python 3.8 and webassembly).
"""
return ZoneInfo(tz)


class IsNow(IsDatetime):
"""
Check if a datetime is close to now, this is similar to `IsDatetime(approx=datetime.now())`,
Expand Down Expand Up @@ -180,7 +172,7 @@ def __init__(
```
"""
if isinstance(tz, str):
tz = _zoneinfo(tz)
tz = ZoneInfo(tz)

self.tz = tz

Expand Down
9 changes: 6 additions & 3 deletions tests/test_datetime.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import sys
from datetime import date, datetime, timedelta, timezone
from unittest.mock import Mock

import pytest

from dirty_equals import IsDate, IsDatetime, IsNow, IsToday

try:
if sys.version_info >= (3, 9):
from zoneinfo import ZoneInfo
except ImportError:
from backports.zoneinfo import ZoneInfo
else:
# This code block is due to a typing issue with backports.zoneinfo package:
# https://github.com/pganssle/zoneinfo/issues/125
from backports.zoneinfo._zoneinfo import ZoneInfo


@pytest.mark.parametrize(
Expand Down

0 comments on commit 6fd0603

Please sign in to comment.