mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
#1277 Add custom types for datetime in Telegram API
This commit adds a new file `custom_types.py` in the aiogram directory. The inclusion of `DateTime` type ensures better compatibility with the Telegram Bot API. `DateTime` type is further enhanced to work with unixtime.
This commit is contained in:
parent
b7be9c2b81
commit
df77ee2436
1 changed files with 17 additions and 0 deletions
17
aiogram/custom_types.py
Normal file
17
aiogram/custom_types.py
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import datetime
|
||||
from typing import Annotated
|
||||
|
||||
from pydantic import PlainSerializer
|
||||
|
||||
# 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",
|
||||
),
|
||||
]
|
||||
|
||||
# Make string compatible with custom lazy proxy
|
||||
# String = Union[str, LazyProxy]
|
||||
Loading…
Add table
Add a link
Reference in a new issue