Skip to content

Add IsTimeAllowed predicate to TimePicker and Clock - #4116

Open
MORTEM3845 wants to merge 1 commit into
MaterialDesignInXAML:masterfrom
MORTEM3845:feature/timepicker-availability-predicate
Open

MORTEM3845 wants to merge 1 commit into
MaterialDesignInXAML:masterfrom
MORTEM3845:feature/timepicker-availability-predicate

Conversation

@MORTEM3845

Copy link
Copy Markdown

Adds a single optional IsTimeAllowed property (Predicate<DateTime>?) to TimePicker and Clock, allowing applications to decide which minute slots can be selected. A null rule preserves unrestricted selection.

For example, appointments can be available from 06:00 through 19:00, every 10 minutes, with a 13:00-14:00 lunch break, using only this property:

picker.IsTimeAllowed = time =>
    time.TimeOfDay >= TimeSpan.FromHours(6)
    && time.TimeOfDay <= TimeSpan.FromHours(19)
    && time.Minute % 10 == 0
    && time.Hour != 13;

The native clock keeps its existing layout and disables unavailable values. The same rule applies to dragging, typed input, and programmatic selection. Programmatic values are coerced to the nearest allowed minute on the same day; invalid typed input follows the existing invalid-text behavior.

Rules receive the selected date and time with seconds cleared: availability is defined per minute, while WithSeconds continues to control seconds selection. If captured application data changes, call RefreshTimeAvailability() to reevaluate the current selection and clock buttons. If no minute is allowed, TimePicker.SelectedTime becomes null and clock choices are disabled.

The existing MinuteSelectionStep behavior is preserved. No additional range or increment properties are introduced.

Addresses #3733.

Validation:

  • Release build for net462, net8.0-windows, and net10.0-windows.
  • Full MaterialDesignThemes.Wpf.Tests suite: 402 passed, 1 pre-existing skipped test, 0 failures.
  • New coverage for range endpoints, lunch breaks, minute steps, manual input and its selected date, dragging, AM/PM consistency, dynamic availability, and empty availability.

This branch has not been deployed

No deployments
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