diff --git a/pyrogram/methods/chats/ban_chat_member.py b/pyrogram/methods/chats/ban_chat_member.py index 8e1bca1e..16a13082 100644 --- a/pyrogram/methods/chats/ban_chat_member.py +++ b/pyrogram/methods/chats/ban_chat_member.py @@ -29,7 +29,7 @@ class BanChatMember: self: "pyrogram.Client", chat_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]: """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 diff --git a/pyrogram/methods/chats/restrict_chat_member.py b/pyrogram/methods/chats/restrict_chat_member.py index 4ebb5f18..717ba60b 100644 --- a/pyrogram/methods/chats/restrict_chat_member.py +++ b/pyrogram/methods/chats/restrict_chat_member.py @@ -30,7 +30,7 @@ class RestrictChatMember: chat_id: Union[int, str], user_id: Union[int, str], permissions: "types.ChatPermissions", - until_date: datetime = datetime.fromtimestamp(0) + until_date: datetime = utils.zero_datetime() ) -> "types.Chat": """Restrict a user in a supergroup. diff --git a/pyrogram/methods/invite_links/edit_chat_invite_link.py b/pyrogram/methods/invite_links/edit_chat_invite_link.py index 29f658ec..99516847 100644 --- a/pyrogram/methods/invite_links/edit_chat_invite_link.py +++ b/pyrogram/methods/invite_links/edit_chat_invite_link.py @@ -51,7 +51,7 @@ class EditChatInviteLink: expire_date (:py:obj:`~datetime.datetime`, *optional*): 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*): Maximum number of users that can be members of the chat simultaneously after joining the chat via this diff --git a/pyrogram/methods/messages/get_chat_history.py b/pyrogram/methods/messages/get_chat_history.py index f21a081f..a7fcc491 100644 --- a/pyrogram/methods/messages/get_chat_history.py +++ b/pyrogram/methods/messages/get_chat_history.py @@ -30,7 +30,7 @@ async def get_chunk( limit: int = 0, offset: int = 0, from_message_id: int = 0, - from_date: datetime = datetime.fromtimestamp(0) + from_date: datetime = utils.zero_datetime() ): messages = await client.invoke( raw.functions.messages.GetHistory( @@ -56,7 +56,7 @@ class GetChatHistory: limit: int = 0, offset: int = 0, offset_id: int = 0, - offset_date: datetime = datetime.fromtimestamp(0) + offset_date: datetime = utils.zero_datetime() ) -> Optional[AsyncGenerator["types.Message", None]]: """Get messages from a chat history. diff --git a/pyrogram/types/user_and_chats/chat.py b/pyrogram/types/user_and_chats/chat.py index e36107bf..7e4442a1 100644 --- a/pyrogram/types/user_and_chats/chat.py +++ b/pyrogram/types/user_and_chats/chat.py @@ -514,7 +514,7 @@ class Chat(Object): async def ban_member( self, user_id: Union[int, str], - until_date: datetime = datetime.fromtimestamp(0) + until_date: datetime = utils.zero_datetime() ) -> Union["types.Message", bool]: """Bound method *ban_member* of :obj:`~pyrogram.types.Chat`. @@ -602,7 +602,7 @@ class Chat(Object): self, user_id: Union[int, str], permissions: "types.ChatPermissions", - until_date: datetime = datetime.fromtimestamp(0), + until_date: datetime = utils.zero_datetime(), ) -> "types.Chat": """Bound method *unban_member* of :obj:`~pyrogram.types.Chat`. diff --git a/pyrogram/utils.py b/pyrogram/utils.py index 18230ed4..b9f3fdd8 100644 --- a/pyrogram/utils.py +++ b/pyrogram/utils.py @@ -23,7 +23,7 @@ import hashlib import os import struct from concurrent.futures.thread import ThreadPoolExecutor -from datetime import datetime +from datetime import datetime, timezone from getpass import getpass 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]: return datetime.fromtimestamp(ts) if ts else None