mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-29 13:27:47 +00:00
Fix zero-datetime not working in some systems
This commit is contained in:
parent
aecdd492eb
commit
8852756798
@ -29,7 +29,7 @@ class BanChatMember:
|
|||||||
self: "pyrogram.Client",
|
self: "pyrogram.Client",
|
||||||
chat_id: Union[int, str],
|
chat_id: Union[int, str],
|
||||||
user_id: Union[int, str],
|
user_id: Union[int, str],
|
||||||
until_date: datetime = datetime.fromtimestamp(0)
|
until_date: datetime = utils.zero_datetime()
|
||||||
) -> Union["types.Message", bool]:
|
) -> Union["types.Message", bool]:
|
||||||
"""Ban a user from a group, a supergroup or a channel.
|
"""Ban a user from a group, a supergroup or a channel.
|
||||||
In the case of supergroups and channels, the user will not be able to return to the group on their own using
|
In the case of supergroups and channels, the user will not be able to return to the group on their own using
|
||||||
|
@ -30,7 +30,7 @@ class RestrictChatMember:
|
|||||||
chat_id: Union[int, str],
|
chat_id: Union[int, str],
|
||||||
user_id: Union[int, str],
|
user_id: Union[int, str],
|
||||||
permissions: "types.ChatPermissions",
|
permissions: "types.ChatPermissions",
|
||||||
until_date: datetime = datetime.fromtimestamp(0)
|
until_date: datetime = utils.zero_datetime()
|
||||||
) -> "types.Chat":
|
) -> "types.Chat":
|
||||||
"""Restrict a user in a supergroup.
|
"""Restrict a user in a supergroup.
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ class EditChatInviteLink:
|
|||||||
|
|
||||||
expire_date (:py:obj:`~datetime.datetime`, *optional*):
|
expire_date (:py:obj:`~datetime.datetime`, *optional*):
|
||||||
Point in time when the link will expire.
|
Point in time when the link will expire.
|
||||||
Defaults to None (no change), pass ``datetime.fromtimestamp(0)`` to set no expiration date.
|
Defaults to None (no change), pass None to set no expiration date.
|
||||||
|
|
||||||
member_limit (``int``, *optional*):
|
member_limit (``int``, *optional*):
|
||||||
Maximum number of users that can be members of the chat simultaneously after joining the chat via this
|
Maximum number of users that can be members of the chat simultaneously after joining the chat via this
|
||||||
|
@ -30,7 +30,7 @@ async def get_chunk(
|
|||||||
limit: int = 0,
|
limit: int = 0,
|
||||||
offset: int = 0,
|
offset: int = 0,
|
||||||
from_message_id: int = 0,
|
from_message_id: int = 0,
|
||||||
from_date: datetime = datetime.fromtimestamp(0)
|
from_date: datetime = utils.zero_datetime()
|
||||||
):
|
):
|
||||||
messages = await client.invoke(
|
messages = await client.invoke(
|
||||||
raw.functions.messages.GetHistory(
|
raw.functions.messages.GetHistory(
|
||||||
@ -56,7 +56,7 @@ class GetChatHistory:
|
|||||||
limit: int = 0,
|
limit: int = 0,
|
||||||
offset: int = 0,
|
offset: int = 0,
|
||||||
offset_id: int = 0,
|
offset_id: int = 0,
|
||||||
offset_date: datetime = datetime.fromtimestamp(0)
|
offset_date: datetime = utils.zero_datetime()
|
||||||
) -> Optional[AsyncGenerator["types.Message", None]]:
|
) -> Optional[AsyncGenerator["types.Message", None]]:
|
||||||
"""Get messages from a chat history.
|
"""Get messages from a chat history.
|
||||||
|
|
||||||
|
@ -514,7 +514,7 @@ class Chat(Object):
|
|||||||
async def ban_member(
|
async def ban_member(
|
||||||
self,
|
self,
|
||||||
user_id: Union[int, str],
|
user_id: Union[int, str],
|
||||||
until_date: datetime = datetime.fromtimestamp(0)
|
until_date: datetime = utils.zero_datetime()
|
||||||
) -> Union["types.Message", bool]:
|
) -> Union["types.Message", bool]:
|
||||||
"""Bound method *ban_member* of :obj:`~pyrogram.types.Chat`.
|
"""Bound method *ban_member* of :obj:`~pyrogram.types.Chat`.
|
||||||
|
|
||||||
@ -602,7 +602,7 @@ class Chat(Object):
|
|||||||
self,
|
self,
|
||||||
user_id: Union[int, str],
|
user_id: Union[int, str],
|
||||||
permissions: "types.ChatPermissions",
|
permissions: "types.ChatPermissions",
|
||||||
until_date: datetime = datetime.fromtimestamp(0),
|
until_date: datetime = utils.zero_datetime(),
|
||||||
) -> "types.Chat":
|
) -> "types.Chat":
|
||||||
"""Bound method *unban_member* of :obj:`~pyrogram.types.Chat`.
|
"""Bound method *unban_member* of :obj:`~pyrogram.types.Chat`.
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ import hashlib
|
|||||||
import os
|
import os
|
||||||
import struct
|
import struct
|
||||||
from concurrent.futures.thread import ThreadPoolExecutor
|
from concurrent.futures.thread import ThreadPoolExecutor
|
||||||
from datetime import datetime
|
from datetime import datetime, timezone
|
||||||
from getpass import getpass
|
from getpass import getpass
|
||||||
from typing import Union, List, Dict, Optional
|
from typing import Union, List, Dict, Optional
|
||||||
|
|
||||||
@ -345,6 +345,10 @@ async def parse_text_entities(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def zero_datetime() -> datetime:
|
||||||
|
return datetime.fromtimestamp(0, timezone.utc)
|
||||||
|
|
||||||
|
|
||||||
def timestamp_to_datetime(ts: Optional[int]) -> Optional[datetime]:
|
def timestamp_to_datetime(ts: Optional[int]) -> Optional[datetime]:
|
||||||
return datetime.fromtimestamp(ts) if ts else None
|
return datetime.fromtimestamp(ts) if ts else None
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user