|
1 | 1 | import json
|
2 | 2 | import logging
|
3 | 3 | import time
|
4 |
| -from datetime import datetime |
| 4 | +from datetime import datetime, UTC |
5 | 5 | from functools import partial
|
6 | 6 | from http.client import HTTPException
|
7 | 7 | from typing import Any, Dict, List, Optional, Tuple, Union
|
@@ -47,7 +47,7 @@ def __init__(
|
47 | 47 | :keyword dict image: image that will be displayed in the embed
|
48 | 48 | :keyword dict provider: information about the provider
|
49 | 49 | :keyword dict thumbnail: thumbnail that will be displayed in the embed
|
50 |
| - :keyword str timestamp: timestamp that will be displayed in the embed |
| 50 | + :keyword float, int, str, datetime timestamp: timestamp that will be displayed in the embed |
51 | 51 | :keyword str title: title of embed
|
52 | 52 | :keyword str url: add an url to make your embedded title a clickable link
|
53 | 53 | :keyword dict video: video that will be displayed in the embed
|
@@ -88,18 +88,21 @@ def set_url(self, url: str) -> None:
|
88 | 88 | self.url = url
|
89 | 89 |
|
90 | 90 | def set_timestamp(
|
91 |
| - self, timestamp: Optional[Union[float, int, datetime]] = None |
| 91 | + self, timestamp: Optional[Union[float, int, str, datetime]] = None |
92 | 92 | ) -> None:
|
93 | 93 | """
|
94 | 94 | Set timestamp of the embed content.
|
95 |
| - :param timestamp: timestamp of embed content |
| 95 | + :param timestamp: optional timestamp of embed content |
96 | 96 | """
|
97 | 97 | if timestamp is None:
|
98 |
| - timestamp = datetime.utcnow() |
| 98 | + timestamp = datetime.now(UTC) |
99 | 99 | elif isinstance(timestamp, float) or isinstance(timestamp, int):
|
100 |
| - timestamp = datetime.utcfromtimestamp(timestamp) |
| 100 | + timestamp = datetime.fromtimestamp(timestamp, UTC).replace(tzinfo=None) |
101 | 101 |
|
102 |
| - self.timestamp = timestamp.isoformat() |
| 102 | + if not isinstance(timestamp, str): |
| 103 | + timestamp = timestamp.isoformat() |
| 104 | + |
| 105 | + self.timestamp = timestamp |
103 | 106 |
|
104 | 107 | def set_color(self, color: Union[str, int]) -> None:
|
105 | 108 | """
|
|
0 commit comments