Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[iOS] Add consistency in date format between platforms #14573

Merged
merged 1 commit into from
Dec 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8" ?>
<local:TestContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:local="using:Xamarin.Forms.Controls"
x:Class="Xamarin.Forms.Controls.Issues.Issue13918"
Title="Issue 13918">
<StackLayout>
<Label
Padding="12"
BackgroundColor="Black"
TextColor="White"
Text="If can see the century in the DatePicker, the test has passed." />
<DatePicker />
</StackLayout>
</local:TestContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Collections.Generic;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;

#if UITEST
using Xamarin.Forms.Core.UITests;
using Xamarin.UITest;
using NUnit.Framework;
#endif

namespace Xamarin.Forms.Controls.Issues
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 13918, "[Bug] iOS DatePicker only displays the last two digits of the year",
PlatformAffected.iOS)]
public partial class Issue13918 : TestContentPage
{
public Issue13918()
{
#if APP
InitializeComponent();
#endif
}

protected override void Init()
{

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1840,6 +1840,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Issue14897.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue14805.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue11954.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue13918.xaml.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Bugzilla22229.xaml">
Expand Down Expand Up @@ -2371,6 +2372,9 @@
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue14897.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue13918.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Bugzilla27417Xaml.xaml">
Expand Down
25 changes: 4 additions & 21 deletions Xamarin.Forms.Platform.iOS/Renderers/DatePickerRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,29 +166,12 @@ void UpdateDateFromModel(bool animate)
{
if (_picker.Date.ToDateTime().Date != Element.Date.Date)
_picker.SetDate(Element.Date.ToNSDate(), animate);

// Can't use Element.Format because it won't display the correct format if the region and language are set differently
if (Element.Format.Equals("d") || Element.Format.Equals("D"))

if (string.IsNullOrWhiteSpace(Element.Format))
{
NSDateFormatter dateFormatter = new NSDateFormatter
{
TimeZone = NSTimeZone.FromGMT(0)
};

if (Element.Format?.Equals("D") == true)
{
dateFormatter.DateStyle = NSDateFormatterStyle.Long;
var strDate = dateFormatter.StringFor(_picker.Date);
Control.Text = strDate;
}
else
{
dateFormatter.DateStyle = NSDateFormatterStyle.Short;
var strDate = dateFormatter.StringFor(_picker.Date);
Control.Text = strDate;
}
Control.Text = Element.Date.ToShortDateString();
}
else if (Element.Format.Contains("/"))
else if (Element.Format.Contains('/'))
{
Control.Text = Element.Date.ToString(Element.Format, CultureInfo.InvariantCulture);
}
Expand Down