reflex-dev / reflex

🕸️ Web apps in pure Python 🐍
https://reflex.dev
Apache License 2.0
20.46k stars 1.18k forks source link

Add datetime to moment #4381

Closed Alek99 closed 1 week ago

Alek99 commented 2 weeks ago

Fair warning this pr was done 100% by ai

"""Welcome to Reflex! This file outlines the steps to create a basic app."""

import reflex as rx
import datetime
from rxconfig import config

class State(rx.State):
    # Test different datetime types
    datetime_val: datetime.datetime = datetime.datetime(2024, 1, 1, 12, 30, 45)
    date_val: datetime.date = datetime.date(2024, 1, 1)
    time_val: datetime.time = datetime.time(12, 30, 45)
    delta_val: datetime.timedelta = datetime.timedelta(days=1, hours=2)

    @rx.var
    def time_as_datetime(self) -> datetime.datetime:
        return datetime.datetime.combine(datetime.date.today(), self.time_val)

    @rx.var
    def delta_as_datetime(self) -> datetime.datetime:
        return datetime.datetime.now() + self.delta_val

def index() -> rx.Component:
    return rx.vstack(
        rx.text("DateTime:"),
        rx.moment(date=State.datetime_val, format="YYYY-MM-DD HH:mm:ss"),
        rx.text("Date:"),
        rx.moment(date=State.date_val, format="YYYY-MM-DD"),
        rx.text("Time:"),
        rx.moment(date=State.time_as_datetime, format="HH:mm:ss"),
        rx.text("Timedelta (from now):"),
        rx.moment(date=State.delta_as_datetime, format="YYYY-MM-DD HH:mm:ss"),
        spacing="4",
    )

app = rx.App()
app.add_page(index)
Screenshot 2024-11-13 at 7 46 49 PM
Alek99 commented 2 weeks ago

closes #4228