mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Fixed TypeError: can't subtract offset-naive and offset-aware datetimes
This commit is contained in:
parent
4705ce0f8e
commit
0784c1549d
1 changed files with 4 additions and 1 deletions
|
|
@ -1,15 +1,18 @@
|
|||
import sys
|
||||
from datetime import datetime
|
||||
|
||||
from datetime import timezone
|
||||
from pydantic import PlainSerializer
|
||||
from typing_extensions import Annotated
|
||||
|
||||
if sys.platform == "win32": # pragma: no cover
|
||||
|
||||
def _datetime_serializer(value: datetime) -> int:
|
||||
tz = timezone.utc if value.tzinfo else None
|
||||
|
||||
# https://github.com/aiogram/aiogram/issues/349
|
||||
# https://github.com/aiogram/aiogram/pull/880
|
||||
return round((value - datetime(1970, 1, 1)).total_seconds())
|
||||
return round((value - datetime(1970, 1, 1, tzinfo=tz)).total_seconds())
|
||||
|
||||
else: # pragma: no cover
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue