Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add datetime to moment #4381

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Add datetime to moment #4381

wants to merge 6 commits into from

Conversation

Alek99
Copy link
Member

@Alek99 Alek99 commented Nov 14, 2024

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 Alek99 marked this pull request as ready for review November 14, 2024 04:07
@Alek99
Copy link
Member Author

Alek99 commented Nov 14, 2024

closes #4228

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant