name: managing-date-selection description: Implements the "Restart Logic" for date range selection in the Tourly search widget. Use when building or modifying the date picker, handling check-in/check-out dates, or implementing calendar interaction algorithms.
Smart Date Range Selection Logic (Tourly)
When to use this skill
- Implementing the date range selection in the search bar or booking forms.
- Modifying
react-day-pickeror Shadcn Calendar behavior to match Tourly's custom "Restart Logic". - Handling edge cases where users select an earlier date than the current start date.
Workflow
- Initialize state for
startDate,endDate, andisCalendarOpen. - Implement the
handleDateSelectalgorithm following the Scenarios below. - Apply visual styles to the input field and calendar cells based on the selection state.
- Ensure the popover only closes on a valid range completion.
The Smart Range Algorithm
Scenario A: Starting Fresh / Resetting
- Condition: No dates selected OR both dates selected and a new date is clicked.
- Action: Set
startDateto selected,endDatetonull. Keep popover OPEN.
Scenario B: Valid Range Completion
- Condition:
startDateexists,endDateisnull, andselectedDate > startDate. - Action: Set
endDateto selected. CLOSE popover.
Scenario C: Backwards Selection (Restart Logic)
- Condition:
startDateexists,endDateisnull, andselectedDate < startDate. - Action: Set
startDateto selected,endDatetonull. Keep popover OPEN. - Note: Do NOT swap dates. Treat this as a correction of the start date.
Visual Requirements
- Input Text: Use low-opacity/gray text (e.g.,
text-muted-foreground) to match placeholder style. - Calendar Header: Must display "Select Dates".
- Highlighting:
- Ends: Solid primary color circles.
- In-between: Light primary background (e.g.,
bg-primary/20) for the range.
Instructions
- Closing Rule: The popover MUST NOT close until Scenario B is met. Automatic closing on the first click is a failure.
- Library Integration: When using
react-day-picker, intercept theonSelectoronDayClickevents to apply this custom logic manualy rather than using the default range mode.