Skip to content

Commit

Permalink
Add datetime to moment (#4381)
Browse files Browse the repository at this point in the history
* Add datetime to moment

* Remove recharts update

* Support other formats

* simplify

* Precommit

* PYI

* change imports for pyi compat

---------

Co-authored-by: Alek Petuskey <alekpetuskey@Aleks-MacBook-Pro.local>
Co-authored-by: Masen Furer <m_github@0x26.net>
  • Loading branch information
3 people authored Nov 19, 2024
1 parent bcea79c commit bffff01
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
7 changes: 4 additions & 3 deletions reflex/components/moment/moment.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Moment component for humanized date rendering."""

import dataclasses
from typing import List, Optional
from datetime import date, datetime, time, timedelta
from typing import List, Optional, Union

from reflex.components.component import NoSSRComponent
from reflex.event import EventHandler, passthrough_event_spec
Expand All @@ -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)

Expand Down Expand Up @@ -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, date, time, timedelta]]

# Shows the duration (elapsed time) between now and the provided datetime.
duration_from_now: Var[bool]
Expand Down
14 changes: 12 additions & 2 deletions reflex/components/moment/moment.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# This file was generated by `reflex/utils/pyi_generator.py`!
# ------------------------------------------------------
import dataclasses
from datetime import date, datetime, time, timedelta
from typing import Any, Dict, Optional, Union, overload

from reflex.components.component import NoSSRComponent
Expand All @@ -20,7 +21,7 @@ class MomentDelta:
weeks: Optional[int]
days: Optional[int]
hours: Optional[int]
minutess: Optional[int]
minutes: Optional[int]
seconds: Optional[int]
milliseconds: Optional[int]

Expand All @@ -46,7 +47,16 @@ class Moment(NoSSRComponent):
decimal: Optional[Union[Var[bool], bool]] = None,
unit: Optional[Union[Var[str], str]] = None,
duration: Optional[Union[Var[str], str]] = None,
date: Optional[Union[Var[str], str]] = None,
date: Optional[
Union[
Var[Union[date, datetime, str, time, timedelta]],
date,
datetime,
str,
time,
timedelta,
]
] = None,
duration_from_now: Optional[Union[Var[bool], bool]] = None,
unix: Optional[Union[Var[bool], bool]] = None,
local: Optional[Union[Var[bool], bool]] = None,
Expand Down

0 comments on commit bffff01

Please sign in to comment.