Excessive Memory Usage when MaxDate is set

I am posting this separately as we are seeing this issue with the latest version of the SfDatePicker control.  I installed 24.1.45 today and we are still having this issue.


Here is the definition of the control 

                <SfDatePicker TValue="DateTime?" @bind-Value="@selectedStartDate" Placeholder="Choose a Date" ShowClearButton="true" StrictMode="true" Min="@MinStartDate" Max="@MaxStartDate"></SfDatePicker>

                <SfDatePicker TValue="DateTime?" @bind-Value="@selectedDueDate" Placeholder="Choose a Date" ShowClearButton="true" StrictMode="true" Min="@MinDueDate" Max="@MaxDueDate"></SfDatePicker>


Here is the C# code 


    public DateTime? selectedStartDate;

    public DateTime? selectedDueDate;

    public DateTime MinStartDate => CurrentJob.CreatedDate;

    public DateTime MaxStartDate => selectedDueDate.HasValue ? selectedDueDate.Value : DateTime.Now.AddYears(1);

    public DateTime MinDueDate => selectedStartDate.HasValue ? selectedStartDate.Value : CurrentJob.CreatedDate;

    public DateTime MaxDueDate => DateTime.Now.AddYears(1);


The CurrentJob object is always initialized when we get to this code and always has a CreatedDate.

The issue only happens if MaxDate property is set, if we remove this the control works correctly.


2 Replies

PK Priyanka Karthikeyan Syncfusion Team January 23, 2024 12:32 PM UTC

Hi Chris Marshall ,

We have considered the reported issue "Unable to select the current date and page gets hanged when we binded the min value as DateTime.Now" as a bug from our end and the fix for the issue will be included with our upcoming patch release which is scheduled at the mid of february.

Now you can track the status of the reported issue through the feedback below,

 

Feedback Link:https://www.syncfusion.com/feedback/50178/unable-to-select-the-current-date-and-page-gets-hanged-when-we-binded-the-min

 

Disclaimer: “Inclusion of this solution in the weekly release may change due to other factors including but not limited to QA checks and works reprioritization.

Meanwhile try using new DateTime() instead of DateTime.Now to resolve this. Please find the sample attached for your reference.
 

Samplehttps://blazorplayground.syncfusion.com/VjVzjWVBegcOUfdp

Regards,

Priyanka K



PK Priyanka Karthikeyan Syncfusion Team February 29, 2024 09:47 AM UTC

Hi Chris Marshall ,

Thank you for bringing this to our attention. In the DatePicker with strict mode, it's essential to note that the selected date value is updated to include the date only, without the time component. For instance, it appears as "02/02/2024 00:00:00". Consequently, when setting the min date as DateTime.Now, the min date stores the date value with seconds, such as "02/02/2024 09:24:34". This discrepancy in time values can result in the DatePicker displaying a date evaluated as smaller than minDate, even if it's on the same day.

To resolve this issue effectively, we recommend setting the minimum date using a specific format.

You can achieve this by employing the following code snippet:

 

new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day)

 

This code snippet creates a new DateTime object with the current year, month, and day, effectively setting the time component to midnight (00:00:00).

By adopting this approach, the minimum date remains consistent and does not include seconds, thereby ensuring consistent behavior in the DatePicker.

Documentation Link : https://blazor.syncfusion.com/documentation/datepicker/strict-mod

Sample Link : https://blazorplayground.syncfusion.com/VjVzjWVBegcOUfdp

Regards,

Priyanka K


Loader.
Up arrow icon