Bug 57265 - Xamarin.Forms.DatePicker isn't setting the MaximumDate correctly on Android
Summary: Xamarin.Forms.DatePicker isn't setting the MaximumDate correctly on Android
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 2.3.5
Hardware: Macintosh Mac OS
: --- blocker
Target Milestone: ---
Assignee: Jimmy [MSFT]
Depends on:
Reported: 2017-06-08 07:12 UTC by Valerio Santinelli
Modified: 2017-10-25 17:48 UTC (History)
4 users (show)

Is this bug a regression?: ---
Last known good build:

sample project (295.67 KB, application/x-zip-compressed)
2017-06-08 21:48 UTC, Jimmy [MSFT]

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Valerio Santinelli 2017-06-08 07:12:02 UTC
# Steps to reproduce

Just create a simple project with a DatePicker and set its MaximumDate to a DateTime like 08/06/2017 23:59:59, show the picker and try to select that date while it runs on Android

# Expected behavior

You should be able to select that day.

# Actual behavior

You see it highlighted like if it was selectable but it isn't

The cause is probably the following line:

Android expects the MaximumDate to be at the end of the day (the time part being 23:59:59) but that function coerces the DateTime value to be with the time set at 00:00:00 and Android doesn't let you select that day as it means to stop the day before.
Comment 1 Jimmy [MSFT] 2017-06-08 21:48:16 UTC
Created attachment 22788 [details]
sample project

I wasn't able to reproduce this issue with a new project using Xamarin.Forms 2.3.4247. 

In the project, I set a MaximumDate and I was able to highlight and select that date. I used a Label to confirm that the DatePicker selected the correct date. I'm attaching the project I used to the report. 

Can you modify the project or attach a new one that reproduces the issue so we can look into this further? When providing the requested information, please set the report's status back to NEW otherwise we may close this issue after 30 days of no response. Thanks!
Comment 2 Jimmy [MSFT] 2017-06-08 21:57:50 UTC
I forgot to mention that I also tested with Xamarin.Forms 2.3.5-pre3 and I still could not reproduce the issue.
Comment 3 Pierre Fournier 2017-06-09 14:44:11 UTC
I have Xamarin.Forms and also have this issue.

My XAML is:
<DatePicker Date="{Binding CurrentDateTime}" Format="yyyy-MM-dd" MinimumDate="{Binding MinimumDate}" MaximumDate="{Binding MaximumDate}" />

My code is:
public DateTime MinimumDate => DateTime.Now.AddDays(-14);
public DateTime MaximumDate => DateTime.Now;

Even though the last day seems accessible (if, for example, I use "DateTime.Now.AddDays(1)" for MaximumDate to differentiate it from today's date), I can't select it.  I did try to remove the "Date" property in case it was preventing the selection, but it didn't help.

Could the culprit be the time of the DateTime? Like, the visual takes care of it but not the selection?
Comment 4 Pierre Fournier 2017-06-09 14:54:06 UTC
@Jimmy: I executed your sample and I get the same result.  Even though I see 06/10/2017 available, I can't click it to change the date.
Comment 5 Rui Marinho 2017-06-20 17:22:05 UTC
You should provide the Date component for the DateTime, that should work.
Comment 6 Valerio Santinelli 2017-10-25 16:47:03 UTC
@Pierre: that's exactly the behavior I'm experiencing. Did you find a solution to this issue?
Comment 7 Valerio Santinelli 2017-10-25 17:10:53 UTC
I've updated the project that had this problem to Xamarin Forms 2.4 and it automagically solved in my case.
Comment 8 Pierre Fournier 2017-10-25 17:48:02 UTC
@Valerio: The date restriction has been removed since so I can't tell if it's still doing it or not.