KEMBAR78
DatePicker: Throws ArgumentOutOfRangeException on WinUI when setting MinimumDate to null · Issue #30922 · dotnet/maui · GitHub
Skip to content

DatePicker: Throws ArgumentOutOfRangeException on WinUI when setting MinimumDate to null #30922

@eli-popova

Description

@eli-popova

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

  1. Add in code:
DatePicker dp = new DatePicker();
dp.MinimumDate = null;
  1. Note: the local time zone offset must be a positive number for the bug to show.
  2. 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)

Relevant log output

Metadata

Metadata

Assignees

Labels

area-controls-pickerPickerp/0Work that we can't release withoutpartner/syncfusionIssues / PR's with Syncfusion collaborationplatform/windowss/triagedIssue has been revieweds/verifiedVerified / Reproducible Issue ready for Engineering Triaget/bugSomething isn't working

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions