Skip to content

Add date range feature#7

Open
Florian-BACHO wants to merge 9 commits intofreddyaboulton:mainfrom
Florian-BACHO:main
Open

Add date range feature#7
Florian-BACHO wants to merge 9 commits intofreddyaboulton:mainfrom
Florian-BACHO:main

Conversation

@Florian-BACHO
Copy link
Copy Markdown

@Florian-BACHO Florian-BACHO commented Mar 21, 2025

Summary of Changes

The native HTML date picker does not support selecting date ranges. To address this limitation, I have replaced the native date picker with Flatpickr, which enables the selection of date ranges.

Closes: #6

Key Changes

  1. New mode Parameter
    A new parameter, mode, has been added to the Calendar component. This parameter allows users to choose between two modes:

    • "date": Enables selection of a single date (default behavior).
    • "range": Enables selection of a date range.
  2. Date Formatting
    The default date format ("YYYY-MM-DD") has been preserved. When a date range is selected, it is formatted as "YYYY-MM-DD to YYYY-MM-DD".

  3. Frontend Updates

    • The change from the native date picker to Flatpickr required adjustments to the frontend, particularly in how dates are selected.
    • The functionality for selecting a single date remains unchanged, but the frontend now leverages Flatpickr for improved date range selection.
  4. Updated predict Function Signature
    The signature of the predict function has been updated to support both single date values and date ranges, particularly when the "range" mode is enabled. The new signature is:

    def predict(value: str | datetime.datetime | tuple[str, str] | tuple[datetime.datetime, datetime.datetime] | None) -> str | datetime.datetime | tuple[str, str] | tuple[datetime.datetime, datetime.datetime] | None:
    • In range mode, the predict function can now accept either a tuple of strings (representing a range of dates) or a tuple of datetime objects.
    • In date mode, the predict function will still accept a single string or datetime object, as before.

Impact on Existing Behavior

  • Single Date Selection: The original behavior for selecting a single date has not been altered.
  • Range Selection: The addition of the "range" mode allows users to select date ranges, which was previously unsupported with the native date picker.
  • predict Function: The predict function now supports both single dates and date ranges, meaning that developers using the function will need to account for the possibility of receiving a tuple of two dates when using range mode.

@freddyaboulton
Copy link
Copy Markdown
Owner

Hi @Florian-BACHO ! Thanks for the contribution and sorry for the delay in reviewing. I'll take a closer look but why did you rename the package?

@Florian-BACHO
Copy link
Copy Markdown
Author

Hi,

I renamed it because I needed it quickly via PyPi for another project and I didn't want it to clash with yours.
We can revert to the original name if you decide to merge the modifications into your project.

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.

Add a date range feature

2 participants