Skip to content
This repository was archived by the owner on Dec 23, 2024. It is now read-only.

Commit 8852756

Browse files
committed
Fix zero-datetime not working in some systems
1 parent aecdd49 commit 8852756

6 files changed

Lines changed: 12 additions & 8 deletions

File tree

pyrogram/methods/chats/ban_chat_member.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ async def ban_chat_member(
2929
self: "pyrogram.Client",
3030
chat_id: Union[int, str],
3131
user_id: Union[int, str],
32-
until_date: datetime = datetime.fromtimestamp(0)
32+
until_date: datetime = utils.zero_datetime()
3333
) -> Union["types.Message", bool]:
3434
"""Ban a user from a group, a supergroup or a channel.
3535
In the case of supergroups and channels, the user will not be able to return to the group on their own using

pyrogram/methods/chats/restrict_chat_member.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ async def restrict_chat_member(
3030
chat_id: Union[int, str],
3131
user_id: Union[int, str],
3232
permissions: "types.ChatPermissions",
33-
until_date: datetime = datetime.fromtimestamp(0)
33+
until_date: datetime = utils.zero_datetime()
3434
) -> "types.Chat":
3535
"""Restrict a user in a supergroup.
3636

pyrogram/methods/invite_links/edit_chat_invite_link.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ async def edit_chat_invite_link(
5151
5252
expire_date (:py:obj:`~datetime.datetime`, *optional*):
5353
Point in time when the link will expire.
54-
Defaults to None (no change), pass ``datetime.fromtimestamp(0)`` to set no expiration date.
54+
Defaults to None (no change), pass None to set no expiration date.
5555
5656
member_limit (``int``, *optional*):
5757
Maximum number of users that can be members of the chat simultaneously after joining the chat via this

pyrogram/methods/messages/get_chat_history.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ async def get_chunk(
3030
limit: int = 0,
3131
offset: int = 0,
3232
from_message_id: int = 0,
33-
from_date: datetime = datetime.fromtimestamp(0)
33+
from_date: datetime = utils.zero_datetime()
3434
):
3535
messages = await client.invoke(
3636
raw.functions.messages.GetHistory(
@@ -56,7 +56,7 @@ async def get_chat_history(
5656
limit: int = 0,
5757
offset: int = 0,
5858
offset_id: int = 0,
59-
offset_date: datetime = datetime.fromtimestamp(0)
59+
offset_date: datetime = utils.zero_datetime()
6060
) -> Optional[AsyncGenerator["types.Message", None]]:
6161
"""Get messages from a chat history.
6262

pyrogram/types/user_and_chats/chat.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ async def set_photo(self, photo: str) -> bool:
514514
async def ban_member(
515515
self,
516516
user_id: Union[int, str],
517-
until_date: datetime = datetime.fromtimestamp(0)
517+
until_date: datetime = utils.zero_datetime()
518518
) -> Union["types.Message", bool]:
519519
"""Bound method *ban_member* of :obj:`~pyrogram.types.Chat`.
520520
@@ -602,7 +602,7 @@ async def restrict_member(
602602
self,
603603
user_id: Union[int, str],
604604
permissions: "types.ChatPermissions",
605-
until_date: datetime = datetime.fromtimestamp(0),
605+
until_date: datetime = utils.zero_datetime(),
606606
) -> "types.Chat":
607607
"""Bound method *unban_member* of :obj:`~pyrogram.types.Chat`.
608608

pyrogram/utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import os
2424
import struct
2525
from concurrent.futures.thread import ThreadPoolExecutor
26-
from datetime import datetime
26+
from datetime import datetime, timezone
2727
from getpass import getpass
2828
from typing import Union, List, Dict, Optional
2929

@@ -345,6 +345,10 @@ async def parse_text_entities(
345345
}
346346

347347

348+
def zero_datetime() -> datetime:
349+
return datetime.fromtimestamp(0, timezone.utc)
350+
351+
348352
def timestamp_to_datetime(ts: Optional[int]) -> Optional[datetime]:
349353
return datetime.fromtimestamp(ts) if ts else None
350354

0 commit comments

Comments
 (0)