Skip to content

Commit 61f34d8

Browse files
authored
fix: wrap timestamp converter (#1477)
1 parent c66fde3 commit 61f34d8

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

interactions/client/utils/attr_converters.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import inspect
22
import typing
3+
import interactions
34
from datetime import datetime
45
from typing import Callable, Union, Any
56

@@ -20,13 +21,18 @@ def timestamp_converter(value: Union[datetime, int, float, str]) -> Timestamp:
2021
A Timestamp object
2122
2223
"""
23-
if isinstance(value, str):
24-
return Timestamp.fromisoformat(value)
25-
if isinstance(value, (float, int)):
26-
return Timestamp.fromtimestamp(float(value))
27-
if isinstance(value, datetime):
28-
return Timestamp.fromdatetime(value)
29-
raise TypeError("Timestamp must be one of: datetime, int, float, ISO8601 str")
24+
try:
25+
if isinstance(value, str):
26+
return Timestamp.fromisoformat(value)
27+
if isinstance(value, (float, int)):
28+
return Timestamp.fromtimestamp(float(value))
29+
if isinstance(value, datetime):
30+
return Timestamp.fromdatetime(value)
31+
raise TypeError("Timestamp must be one of: datetime, int, float, ISO8601 str")
32+
except ValueError as e:
33+
interactions.const.get_logger().warning("Failed to convert timestamp", exc_info=e)
34+
# Should only happen if the timestamp is something stupid like 269533-01-01T00:00 - in which case we just return MISSING
35+
return MISSING
3036

3137

3238
def list_converter(converter) -> Callable[[list], list]:

0 commit comments

Comments
 (0)