question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Enhancement] DatePicker and TimePicker should support DateOnly? and TimeOnly?

See original GitHub issue

Merging #1847

Summary

  • DatePicker and TimePicker should use the new DateOnly and TimeOnly structs instead of DateTime
  • 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:open
  • Created 2 years ago
  • Reactions:24
  • Comments:52 (10 by maintainers)

github_iconTop GitHub Comments

15reactions
msftbot[bot]commented, Aug 12, 2022

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.

7reactions
KPixelcommented, Feb 18, 2022

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found