1
1
import inspect
2
2
import typing
3
+ import interactions
3
4
from datetime import datetime
4
5
from typing import Callable , Union , Any
5
6
@@ -20,13 +21,18 @@ def timestamp_converter(value: Union[datetime, int, float, str]) -> Timestamp:
20
21
A Timestamp object
21
22
22
23
"""
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
30
36
31
37
32
38
def list_converter (converter ) -> Callable [[list ], list ]:
0 commit comments