From 7cb43c0a23e86fcbf32781de54a84c688a73a406 Mon Sep 17 00:00:00 2001 From: Mahmut Date: Fri, 20 Aug 2021 14:01:11 +0300 Subject: [PATCH] Refactor for iOS DateTimeKind.Unspecified Conversion --- DateTimePopups/DateTimePopups.csproj | 8 ++++---- DateTimePopups/DateTimePopups.ios.cs | 11 +++++++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/DateTimePopups/DateTimePopups.csproj b/DateTimePopups/DateTimePopups.csproj index e475ff2..1643ada 100644 --- a/DateTimePopups/DateTimePopups.csproj +++ b/DateTimePopups/DateTimePopups.csproj @@ -10,10 +10,10 @@ Xamarin.DateTimePopups Little library of popups for picking dates and times $(AssemblyName) ($(TargetFramework)) - 1.0.0.2 - 1.0.0.2 - 1.0.0.2 - 1.0.0.2 + 1.0.0.3 + 1.0.0.3 + 1.0.0.3 + 1.0.0.3 dimonovdd dimonovdd https://github.com/dimonovdd/Xamarin.DateTimePopups diff --git a/DateTimePopups/DateTimePopups.ios.cs b/DateTimePopups/DateTimePopups.ios.cs index fd3cd25..76c00ea 100644 --- a/DateTimePopups/DateTimePopups.ios.cs +++ b/DateTimePopups/DateTimePopups.ios.cs @@ -22,16 +22,23 @@ public static partial class DateTimePopups { var tcs = new TaskCompletionSource(); + DateTime defaultDate = selectedDate ?? DateTime.Now; + + if (defaultDate.Kind == DateTimeKind.Unspecified) + { + defaultDate = DateTime.SpecifyKind(defaultDate, DateTimeKind.Local); + } + var dialog = new DatePickerDialog(useLocalizedButtons: true); dialog.Show( null, isTime ? UIDatePickerMode.Time : UIDatePickerMode.Date, (date) => tcs.TrySetResult(date), - selectedDate ?? DateTime.Now, + defaultDate, maxDate, minDate, () => tcs.TrySetResult(null), - Platform.getCurrentViewFunc); + Platform.getCurrentViewFunc); return tcs.Task; }