mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
* #1277 Replace datetime.datetime with DateTime across codebase Replaced all instances of standard library 'datetime.datetime' with a new 'DateTime' type from `.custom` module. This change is necessary to make all date-time values compatible with the Telegram Bot API (it uses Unix time). This will simplify the conversion process and eliminate potential errors related to date-time format mismatches. Changed codebase, butcher files, and modified 'pyproject.toml' to shift the typing-extensions dependency. The 'aiogram/custom_types.py' file was renamed to 'aiogram/types/custom.py' to better reflect its nature as a location for custom types used in the aiogram library.
14 lines
343 B
Python
14 lines
343 B
Python
from datetime import datetime
|
|
|
|
from pydantic import PlainSerializer
|
|
from typing_extensions import Annotated
|
|
|
|
# Make datetime compatible with Telegram Bot API (unixtime)
|
|
DateTime = Annotated[
|
|
datetime,
|
|
PlainSerializer(
|
|
func=lambda dt: int(dt.timestamp()),
|
|
return_type=int,
|
|
when_used="json-unless-none",
|
|
),
|
|
]
|