Skip to content

Commit

Permalink
test: use pendulum
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravio1i committed Nov 1, 2021
1 parent 7c3c2f5 commit 3226a0d
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 12 deletions.
11 changes: 7 additions & 4 deletions notion_gcal_sync/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
import re
from datetime import datetime, date

import pytz
import pendulum


class Time:
def __init__(self, timezone_name: str):
self.timezone_name = timezone_name
self.timezone = pytz.timezone(self.timezone_name)
self.timezone = pendulum.timezone(self.timezone_name)

@staticmethod
def is_date(dt: datetime or str) -> bool or None:
Expand Down Expand Up @@ -37,7 +37,7 @@ def datetime_to_str_date(dt: datetime) -> str or None:

@staticmethod
def now() -> str:
return datetime.now().isoformat("T", "seconds")
return datetime.now().isoformat("T", "minutes")

def to_datetime(self, dt: str or datetime or date) -> datetime or date or None:
if type(dt) == datetime or type(dt) == date:
Expand All @@ -58,4 +58,7 @@ def str_to_datetime(self, date_str: str) -> datetime or date or None:
return datetime.strptime(date_str, "%Y-%m-%d").date()

dt = datetime.fromisoformat(date_str).replace(second=0, microsecond=0)
return dt.astimezone(self.timezone)
if dt.tzinfo is None:
dt = dt.replace(tzinfo=self.timezone)
dt = dt.astimezone(self.timezone)
return dt
49 changes: 48 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ google-auth-oauthlib = "0.4.6"
pyyaml = "5.4.1"
pandas = "1.3.3"
click = "^8.0.3"
pytz = "^2021.3"
pendulum = "^2.1.2"

[tool.poetry.dev-dependencies]
pytest = "6.2.4"
Expand Down
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ pyyaml==5.4.1
pandas==1.3.3
setuptools~=58.0.4
click~=8.0.3

pip~=21.2.4
toml~=0.10.2
zlib~=1.2.11
Expand All @@ -15,4 +14,4 @@ cryptography~=35.0.0
py~=1.10.0
docutils~=0.17.1
pytest~=6.2.4
pytz~=2021.3
pendulum~=2.1.2
8 changes: 4 additions & 4 deletions tests/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from zoneinfo import ZoneInfo

import pytest
import pytz
import pendulum

from notion_gcal_sync.utils import Time

Expand Down Expand Up @@ -56,9 +56,9 @@ def test_datetime_to_str_date(test_input, expected):
@pytest.mark.parametrize(
"test_input, expected",
[
("Europe/Berlin", pytz.timezone("Europe/Berlin")),
("UTC", pytz.timezone("UTC")),
("America/Los_Angeles", pytz.timezone("America/Los_Angeles")),
("Europe/Berlin", pendulum.timezone("Europe/Berlin")),
("UTC", pendulum.timezone("UTC")),
("America/Los_Angeles", pendulum.timezone("America/Los_Angeles")),
],
)
def test_time(test_input, expected):
Expand Down

0 comments on commit 3226a0d

Please sign in to comment.