summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.WinRT
diff options
context:
space:
mode:
authorJimmy Garrido <jimmygarrido@outlook.com>2017-09-12 05:16:25 -0700
committerKangho Hur <kangho.hur@samsung.com>2017-10-23 13:30:51 +0900
commit89ae5eca1b8fabc6431fdc42c7cc1f96ff708bc6 (patch)
tree9ac4e54af76284d1f53d227544f88309c5418f75 /Xamarin.Forms.Platform.WinRT
parent6b94227a9c86bd403837ff861abf19c2f30f8bd0 (diff)
downloadxamarin-forms-89ae5eca1b8fabc6431fdc42c7cc1f96ff708bc6.tar.gz
xamarin-forms-89ae5eca1b8fabc6431fdc42c7cc1f96ff708bc6.tar.bz2
xamarin-forms-89ae5eca1b8fabc6431fdc42c7cc1f96ff708bc6.zip
[UWP] Prevent crash when using DateTime.MinValue (#1056)
Diffstat (limited to 'Xamarin.Forms.Platform.WinRT')
-rw-r--r--Xamarin.Forms.Platform.WinRT/DatePickerRenderer.cs16
1 files changed, 14 insertions, 2 deletions
diff --git a/Xamarin.Forms.Platform.WinRT/DatePickerRenderer.cs b/Xamarin.Forms.Platform.WinRT/DatePickerRenderer.cs
index 005d30ce..77f05236 100644
--- a/Xamarin.Forms.Platform.WinRT/DatePickerRenderer.cs
+++ b/Xamarin.Forms.Platform.WinRT/DatePickerRenderer.cs
@@ -90,13 +90,25 @@ namespace Xamarin.Forms.Platform.WinRT
void UpdateMaximumDate()
{
DateTime maxdate = Element.MaximumDate;
- Control.MaxYear = new DateTimeOffset(maxdate.Date);
+ Control.MaxYear = new DateTimeOffset(maxdate);
}
void UpdateMinimumDate()
{
DateTime mindate = Element.MinimumDate;
- Control.MinYear = new DateTimeOffset(mindate);
+
+ try
+ {
+ Control.MinYear = new DateTimeOffset(mindate);
+ }
+ catch (ArgumentOutOfRangeException)
+ {
+ // This will be thrown when mindate equals DateTime.MinValue and the UTC offset is positive
+ // because the resulting DateTimeOffset.UtcDateTime will be out of range. In that case let's
+ // specify the Kind as UTC so there is no offset.
+ mindate = DateTime.SpecifyKind(mindate, DateTimeKind.Utc);
+ Control.MinYear = new DateTimeOffset(mindate);
+ }
}
void UpdateTextColor()