|
16 | 16 | # You should have received a copy of the GNU Lesser General Public License |
17 | 17 | # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. |
18 | 18 |
|
19 | | -from concurrent.futures.thread import ThreadPoolExecutor |
20 | | -from datetime import datetime, timezone |
21 | | -from getpass import getpass |
22 | | -from io import BytesIO |
23 | | -from typing import Union, List, Dict, Optional |
24 | 19 | import asyncio |
25 | 20 | import base64 |
26 | 21 | import functools |
27 | 22 | import hashlib |
28 | 23 | import os |
29 | 24 | import re |
30 | 25 | import struct |
| 26 | +from concurrent.futures.thread import ThreadPoolExecutor |
| 27 | +from datetime import datetime, timedelta, timezone |
| 28 | +from getpass import getpass |
| 29 | +from io import BytesIO |
| 30 | +from typing import Dict, List, Optional, Union |
31 | 31 |
|
32 | 32 | import pyrogram |
33 | | -from pyrogram import raw, enums |
34 | | -from pyrogram import types |
| 33 | +from pyrogram import enums, raw, types |
| 34 | +from pyrogram.file_id import DOCUMENT_TYPES, PHOTO_TYPES, FileId, FileType |
35 | 35 | from pyrogram.types.messages_and_media.message import Str |
36 | | -from pyrogram.file_id import FileId, FileType, PHOTO_TYPES, DOCUMENT_TYPES |
37 | 36 |
|
38 | 37 |
|
39 | 38 | async def ainput(prompt: str = "", *, hide: bool = False, loop: Optional[asyncio.AbstractEventLoop] = None): |
@@ -531,8 +530,11 @@ def timestamp_to_datetime(ts: Optional[int]) -> Optional[datetime]: |
531 | 530 | return datetime.fromtimestamp(ts) if ts else None |
532 | 531 |
|
533 | 532 |
|
534 | | -def datetime_to_timestamp(dt: Optional[datetime]) -> Optional[int]: |
535 | | - return int(dt.timestamp()) if dt else None |
| 533 | +def datetime_to_timestamp(dt: Optional[Union[datetime, timedelta]]) -> Optional[int]: |
| 534 | + if isinstance(dt, timedelta): |
| 535 | + return int((datetime.now() + dt).timestamp()) |
| 536 | + elif isinstance(dt, datetime): |
| 537 | + return int(dt.timestamp()) |
536 | 538 |
|
537 | 539 |
|
538 | 540 | def get_first_url(text): |
|
0 commit comments