Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to DateOnly and TimeOnly Types in Pickers #7364

Open
robloo opened this issue Jan 15, 2022 · 4 comments
Open

Switch to DateOnly and TimeOnly Types in Pickers #7364

robloo opened this issue Jan 15, 2022 · 4 comments

Comments

@robloo
Copy link
Contributor

robloo commented Jan 15, 2022

Describe the feature you'd like

The DatePicker and TimePicker could be switched over to the new .NET 6 types for DateOnly and TimeOnly. Especially for the DatePicker, this could eliminate some potential issues with DateTimeOffset unexpectedly using certain time zone values.

As this would break existing apps and require .NET6, this should not be done for a few years. Perhaps around .NET 7/8 it would make sense to switch corresponding to the next major release of Avalonia that allows breaking changes.

Affected controls:

  • DatePicker
  • TimePicker
  • Calendar
  • CalendarDatePicker

Describe alternatives you've considered

  1. Alternative is no changes.
  2. Two selected value properties are provided: one for the old type, one for the new (idea discussed below)

Additional context

Date, Time, and Time Zone Enhancements in .NET 6

@maxkatz6
Copy link
Member

As this would break existing apps and require .NET6

It won't break anything, if we add additional property for that. Moreover, next major release would be right time to do it, and not wait for .NET 7/8. Old property can be deprecated.
The problem is naming though.
It can be either this (no breaking change):

class TimePicker
{
   TimeSpan SelectedTime { get; set; }
#if NET6_OR_HIGHER
   TimeOnly SelectedTimeOnly { get; set; }
#endif
}

Or this (with breaking change, but easy workaround):

class TimePicker
{
#if NET6_OR_HIGHER
   TimeOnly SelectedTime { get; set; }
#endif
   TimeSpan SelectedTimeSpan { get; set; }
}

What is true that we definitely can't remove old TimeSpan/DateTime properties. It's pure pain, when two different targets of the same version have two API sets with same naming but different types.

@maxkatz6
Copy link
Member

I personally would prefer new SelectedTimeOnly and SelectedDateOnly properties

@maxkatz6
Copy link
Member

Though, on a second though, it would require quite a lot of API to duplicate. There also a DisplayDateStart, DisplayDateEnd and same for time picker. Not to mention internal logic should use new types where possible and fallback to old types on older targets.
Sadly, we can't really drop anything older than .NET 6 in near future as well to simplify it.

@robloo
Copy link
Contributor Author

robloo commented Jan 16, 2022

We dare not duplicate the API and create new properties. This needs to be a clean breaking changes that: 1. Simplifies usage (important) and 2. Prevents possible time zone errors 3. Modernizes types.

I was clear this might not be possible for some time. But when we are ready to set .net 6 as minimum it should be done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants