Add datetime to moment
This commit is contained in:
parent
853a9d8614
commit
7c857f9c1f
@ -1,7 +1,8 @@
|
||||
"""Moment component for humanized date rendering."""
|
||||
|
||||
import dataclasses
|
||||
from typing import List, Optional
|
||||
import datetime
|
||||
from typing import List, Optional, Union
|
||||
|
||||
from reflex.components.component import NoSSRComponent
|
||||
from reflex.event import EventHandler, passthrough_event_spec
|
||||
@ -19,7 +20,7 @@ class MomentDelta:
|
||||
weeks: Optional[int] = dataclasses.field(default=None)
|
||||
days: Optional[int] = dataclasses.field(default=None)
|
||||
hours: Optional[int] = dataclasses.field(default=None)
|
||||
minutess: Optional[int] = dataclasses.field(default=None)
|
||||
minutes: Optional[int] = dataclasses.field(default=None)
|
||||
seconds: Optional[int] = dataclasses.field(default=None)
|
||||
milliseconds: Optional[int] = dataclasses.field(default=None)
|
||||
|
||||
@ -78,7 +79,7 @@ class Moment(NoSSRComponent):
|
||||
duration: Var[str]
|
||||
|
||||
# The date to display (also work if passed as children).
|
||||
date: Var[str]
|
||||
date: Var[Union[str, datetime.datetime, datetime.date]]
|
||||
|
||||
# Shows the duration (elapsed time) between now and the provided datetime.
|
||||
duration_from_now: Var[bool]
|
||||
|
@ -262,6 +262,9 @@ class Cartesian(Recharts):
|
||||
# The layout of bar in the chart, usually inherited from parent. 'horizontal' | 'vertical'
|
||||
layout: Var[LiteralLayout]
|
||||
|
||||
# The source data, in which each element is an object.
|
||||
data: Var[List[Dict[str, Any]]]
|
||||
|
||||
# The key of a group of data which should be unique in an area chart.
|
||||
data_key: Var[Union[str, int]]
|
||||
|
||||
@ -656,11 +659,35 @@ class Reference(Recharts):
|
||||
# Defines how to draw the reference line if it falls partly outside the canvas. If set to 'discard', the reference line will not be drawn at all. If set to 'hidden', the reference line will be clipped to the canvas. If set to 'visible', the reference line will be drawn completely. If set to 'extendDomain', the domain of the overflown axis will be extended such that the reference line fits into the canvas. Default: "discard"
|
||||
if_overflow: Var[LiteralIfOverflow]
|
||||
|
||||
# If set true, the line will be rendered in front of bars in BarChart, etc. Default: False
|
||||
is_front: Var[bool]
|
||||
|
||||
# If set a string or a number, default label will be drawn, and the option is content.
|
||||
label: Var[Union[str, int]]
|
||||
|
||||
# If set true, the line will be rendered in front of bars in BarChart, etc. Default: False
|
||||
is_front: Var[bool]
|
||||
# The customized event handler of click on the component in this chart
|
||||
on_click: EventHandler[no_args_event_spec]
|
||||
|
||||
# The customized event handler of mousedown on the component in this chart
|
||||
on_mouse_down: EventHandler[no_args_event_spec]
|
||||
|
||||
# The customized event handler of mouseup on the component in this chart
|
||||
on_mouse_up: EventHandler[no_args_event_spec]
|
||||
|
||||
# The customized event handler of mouseover on the component in this chart
|
||||
on_mouse_over: EventHandler[no_args_event_spec]
|
||||
|
||||
# The customized event handler of mouseout on the component in this chart
|
||||
on_mouse_out: EventHandler[no_args_event_spec]
|
||||
|
||||
# The customized event handler of mouseenter on the component in this chart
|
||||
on_mouse_enter: EventHandler[no_args_event_spec]
|
||||
|
||||
# The customized event handler of mousemove on the component in this chart
|
||||
on_mouse_move: EventHandler[no_args_event_spec]
|
||||
|
||||
# The customized event handler of mouseleave on the component in this chart
|
||||
on_mouse_leave: EventHandler[no_args_event_spec]
|
||||
|
||||
|
||||
class ReferenceLine(Reference):
|
||||
|
@ -289,6 +289,13 @@ def serialize_datetime(dt: Union[date, datetime, time, timedelta]) -> str:
|
||||
Returns:
|
||||
The serialized datetime.
|
||||
"""
|
||||
if isinstance(dt, datetime):
|
||||
return dt.isoformat()
|
||||
elif isinstance(dt, date):
|
||||
return dt.isoformat()
|
||||
elif isinstance(dt, time):
|
||||
return dt.isoformat()
|
||||
else: # timedelta
|
||||
return str(dt)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user