-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
Description
When I create a DatePicker control and set MinimumDate or Date to null as they are now nullable properties, the control throws ArgumentOutOfRangeException on WinUI with the message: The UTC time represented when the offset is applied must be between year 0 and 10,000. (Parameter 'offset').
As I see, setting MinimumDate = null, results in platformDatePicker.MinDate = datePicker?.MinimumDate ?? DateTime.MinValue. However, this creates a DateTimeOffset struct with DateTime 1/1/0001 12:00:00 AM and local system time zone offset (in my case + 3) which converted to UTC is 0000-12-31 21:00:00 which is below the valid value for DateTimeOffset's MinValue which is 1/1/0001 12:00:00 AM UTC. and thus the exception.
The same issue appears when setting the Date property and can happen for the MaximumDate property as well.
Steps to Reproduce
- Add in code:
DatePicker dp = new DatePicker();
dp.MinimumDate = null;
- Note: the local time zone offset must be a positive number for the bug to show.
- See the exception on WinUI.
Link to public reproduction project repository
No response
Version with bug
10.0.0-preview.6
Is this a regression from previous behavior?
Yes, this used to work in .NET MAUI
Last version that worked well
Unknown/Other
Affected platforms
Windows
Affected platform versions
No response
Did you find any workaround?
Workaround is to not set MinimumDate, or set a valid MinimumDate value, or if I want exactly the value of DateTime.MinValue to set it like:
dp.MinimumValue = DateTime.SpecifyKind(DateTime.MinValue, DateTimeKind.Utc)