Skip to content

Commit d675e51

Browse files
committed
🔨 feat: from pytz to zoneinfo
1 parent 4f85ea9 commit d675e51

File tree

5 files changed

+30
-54
lines changed

5 files changed

+30
-54
lines changed

app/schemas/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import abc
22
from datetime import datetime
3+
from zoneinfo import ZoneInfo
34

4-
import pytz
55
from pydantic import BaseModel, ConfigDict, model_validator
66
from typing_extensions import Self
77

@@ -20,6 +20,6 @@ class BaseResponse(BaseModel, abc.ABC):
2020

2121
@model_validator(mode="after")
2222
def set_timezone(self) -> Self:
23-
self.created_at = self.created_at.astimezone(pytz.timezone(configs.TZ))
24-
self.updated_at = self.updated_at.astimezone(pytz.timezone(configs.TZ))
23+
self.created_at = self.created_at.astimezone(ZoneInfo(configs.TZ))
24+
self.updated_at = self.updated_at.astimezone(ZoneInfo(configs.TZ))
2525
return self

app/schemas/responses.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from datetime import datetime
22
from typing import Generic, TypeVar
3+
from zoneinfo import ZoneInfo
34

4-
import pytz
55
from pydantic import BaseModel
66

77
from app.core.configs import configs
@@ -40,7 +40,7 @@ def success(cls, *, status: int, data: T) -> "APIResponse[T]":
4040
status=status,
4141
message="The request has been successfully processed.",
4242
data=data,
43-
timestamp=datetime.now().astimezone(pytz.timezone(configs.TZ)),
43+
timestamp=datetime.now().astimezone(ZoneInfo(configs.TZ)),
4444
)
4545

4646
@classmethod
@@ -49,5 +49,5 @@ def error(cls, *, status: int, message: str) -> "APIResponse[T]":
4949
status=status,
5050
message=message,
5151
data=None,
52-
timestamp=datetime.now().astimezone(pytz.timezone(configs.TZ)),
52+
timestamp=datetime.now().astimezone(ZoneInfo(configs.TZ)),
5353
)

app/services/auth.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from datetime import datetime, timedelta
22
from typing import overload
3+
from zoneinfo import ZoneInfo
34

45
import httpx
5-
import pytz
66
from jose import jwt
77
from jose.exceptions import ExpiredSignatureError, JWTError
88
from loguru import logger
@@ -64,8 +64,8 @@ def __init__(self) -> None:
6464
def _encode(self, *, sub: str, exp: timedelta) -> str:
6565
payload = JwtPayload(
6666
sub=sub,
67-
iat=datetime.now().astimezone(pytz.timezone(configs.TZ)),
68-
exp=datetime.now().astimezone(pytz.timezone(configs.TZ)) + exp,
67+
iat=datetime.now().astimezone(ZoneInfo(configs.TZ)),
68+
exp=datetime.now().astimezone(ZoneInfo(configs.TZ)) + exp,
6969
)
7070
return jwt.encode(
7171
claims=payload.model_dump(), key=self.secret, algorithm=self.algorithm

pyproject.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ dependencies = [
1717
"pydantic[email]>=2.10.5",
1818
"python-jose>=3.3.0",
1919
"python-multipart>=0.0.20",
20-
"pytz>=2024.2",
2120
"sqlalchemy>=2.0.38",
2221
"uv>=0.5.21",
2322
"uvicorn[standard]>=0.34.0",
@@ -33,7 +32,6 @@ lint = [
3332
"sqlalchemy[mypy]>=2.0.38",
3433
"types-passlib>=1.7.7.20241221",
3534
"types-python-jose>=3.3.4.20240106",
36-
"types-pytz>=2024.2.0.20241221",
3735
]
3836
test = [
3937
"pytest>=8.3.4",

uv.lock

Lines changed: 21 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)