Support other formats
This commit is contained in:
parent
a7f81bbe4d
commit
436a15a720
@ -79,7 +79,7 @@ class Moment(NoSSRComponent):
|
|||||||
duration: Var[str]
|
duration: Var[str]
|
||||||
|
|
||||||
# The date to display (also work if passed as children).
|
# The date to display (also work if passed as children).
|
||||||
date: Var[Union[str, datetime.datetime, datetime.date]]
|
date: Var[Union[str, datetime.datetime, datetime.date, datetime.time, datetime.timedelta]]
|
||||||
|
|
||||||
# Shows the duration (elapsed time) between now and the provided datetime.
|
# Shows the duration (elapsed time) between now and the provided datetime.
|
||||||
duration_from_now: Var[bool]
|
duration_from_now: Var[bool]
|
||||||
|
@ -289,14 +289,8 @@ def serialize_datetime(dt: Union[date, datetime, time, timedelta]) -> str:
|
|||||||
Returns:
|
Returns:
|
||||||
The serialized datetime.
|
The serialized datetime.
|
||||||
"""
|
"""
|
||||||
if isinstance(dt, datetime):
|
# Use isoformat for datetime-like objects, str for timedelta
|
||||||
return dt.isoformat()
|
return getattr(dt, 'isoformat', lambda: str(dt))()
|
||||||
elif isinstance(dt, date):
|
|
||||||
return dt.isoformat()
|
|
||||||
elif isinstance(dt, time):
|
|
||||||
return dt.isoformat()
|
|
||||||
else: # timedelta
|
|
||||||
return str(dt)
|
|
||||||
|
|
||||||
|
|
||||||
@serializer(to=str)
|
@serializer(to=str)
|
||||||
|
Loading…
Reference in New Issue
Block a user