[Enhancement] DatePicker and TimePicker should support DateOnly? and TimeOnly?
See original GitHub issueMerging #1847
Summary
DatePicker
andTimePicker
should use the newDateOnly
andTimeOnly
structs instead ofDateTime
- The new fields should be nullable
- The new fields should be added to the Core implementation of MAUI
- The old properties should continue to exist in Controls, be marked as Obsolete, and wrap the new properties from Core
API Proposed:
Core:
public partial interface IDatePicker
{
DateOnly? Value { get; set; }
DateOnly? MinimumValue { get; }
DateOnly? MaximumValue { get; }
}
public partial interface ITimePicker
{
TimeOnly? Value { get; }
}
Controls:
public partial class DatePicker
{
DateOnly? Value { get; set; }
DateOnly? MinimumValue { get; set; }
DateOnly? MaximumValue { get; set; }
[Obsolete($"Use {nameof(Value)} instead.")]
DateTime Date
{
get => Value?.ToDateTime(TimeOnly.MinValue) ?? DateTime.MinValue;
set => Value = DateOnly.FromDateTime(value);
}
[Obsolete($"Use {nameof(MinimumValue)} instead.")]
DateTime MinimumDate
{
get => MinimumValue?.ToDateTime(TimeOnly.MinValue) ?? DateTime.MinValue;
set => MinimumValue = DateOnly.FromDateTime(value);
}
[Obsolete($"Use {nameof(MaximumValue)} instead.")]
DateTime MaximumDate
{
get => MaximumValue?.ToDateTime(TimeOnly.MinValue) ?? DateTime.MinValue;
set => MaximumValue = DateOnly.FromDateTime(value);
}
}
public partial class TimePicker
{
TimeOnly? Value { get; set; }
[Obsolete($"Use {nameof(Value)} instead.")]
TimeSpan Time
{
get => Value?.ToTimeSpan() ?? TimeSpan.Zero;
set => Value = TimeOnly.FromTimeSpan(value);
}
}
ORIGINAL POST:
Summary
I wish DatePicker
had a Date property that was nullable, so that we could use it for optional dates.
API Changes
My suggestion is to follow how UWP/WinUI resolved this issue in a backward-compatible way: They added another property.
public System.DateOnly? SelectedDate { get; set; }
It would go in both DatePicker
and IDatePicker (which doesn’t need to be back-compat).
By the way, I used the new DateOnly instead of DateTime
. But I’m fine if that’s not feasible.
Intended Use Case
Currently, it is a pain to build an app that allows users to provide an optional date. One workaround is to add a checkbox to “activate” entering that date, but that is really not user-friendly.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:24
- Comments:52 (10 by maintainers)
Top Results From Across the Web
DateOnly/TimeOnly support in UI for Blazor
Hi, I try tu use the new Date/TimeOnly types of .Net6 and they are not supported by the Telerik components (you cannot bind...
Read more >adopt the TimeOnly and DateOnly types released in .NET 6
Currently, RadDateTimePicker offers a Value property, typeof(DateTime) even though the control is designed to manage only date and only time ...
Read more >Provide support for DateOnly and TimeOnly type ...
Check out the feature request in Blazor - DatePicker - Provide support for DateOnly and TimeOnly type for calendar components.
Read more >How to Create a WordPress Date Picker Form [Without Code]
WordPress date picker forms are easy to create with the right plugin. ... this field to include both date and time, date only,...
Read more >Date Time Picker Form Cell
The form cell can be used in four different modes: date and time, date range, date only, or time only. Date-Time¶. This is...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
We’ve moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.
@rmarinho @hartez @Redth Please, let’s not forget about this issue.
After MAUI goes into RC, you will probably consider this change as breaking, and at that time, it will be impossible to add.