This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
#12556 * fix date and time picker localizations * fixed UWP datepicker * edited UWP datepicker * added UI tests for datetime picker localization * Fixes #11472 Fixes #11471 * fixes #11471 fixes #11472 * fixes #11471 fixes #11472 * fixes #11471 #11472 * fixes #11471 #11472 * fixes #11471 #11472 * reverted csproj * fixes #11471 #11472 * fixes #11471 #11472 * fixes #11471 #11472 * fixes #11471 #11472 * fixes #11471 #11472 * fixes #11471 #11472 * fixes #11471 #11472 * Update Xamarin.Forms.ControlGallery.Tizen.csproj * Update ErrorMessages.Designer.cs * - fix uwp Co-authored-by: Shane Neuville <shneuvil@microsoft.com>
- Loading branch information
Showing
22 changed files
with
612 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
Xamarin.Forms.ControlGallery.iOS/GalleryPages/RegionalLocale.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
using Foundation; | ||
using Xamarin.Forms; | ||
using Xamarin.Forms.Controls.GalleryPages.DateTimePickerGalleries; | ||
|
||
[assembly: Dependency(typeof(Xamarin.Forms.ControlGallery.iOS.GalleryPages.RegionalLocale))] | ||
namespace Xamarin.Forms.ControlGallery.iOS.GalleryPages | ||
{ | ||
public class RegionalLocale : ILocalize | ||
{ | ||
public string GetCurrentCultureInfo() | ||
{ | ||
string iOSLocale = NSLocale.CurrentLocale.CountryCode; | ||
string iOSLanguage = NSLocale.CurrentLocale.LanguageCode; | ||
return iOSLanguage + "-" + iOSLocale; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
...s.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/DateTimePickerLocalizationTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
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 | ||
{ | ||
#if UITEST | ||
[Category(UITestCategories.DatePicker)] | ||
#endif | ||
[Preserve(AllMembers = true)] | ||
[Issue(IssueTracker.Github, 11472, "DateTime Localization Issue", | ||
PlatformAffected.iOS | PlatformAffected.Android)] | ||
public class DateTimeLocalizationTests : TestNavigationPage | ||
{ | ||
protected override void Init() | ||
{ | ||
#if APP | ||
PushAsync(new GalleryPages.DateTimePickerGalleries.DateTimePickerGallery()); | ||
#endif | ||
} | ||
|
||
#if UITEST | ||
|
||
public string TimeString(String format, String time) | ||
{ | ||
RunningApp.ClearText("timeFormatString"); | ||
RunningApp.EnterText("timeFormatString", format); | ||
RunningApp.PressEnter(); | ||
RunningApp.ClearText("settingTime"); | ||
RunningApp.EnterText("settingTime", time); | ||
RunningApp.PressEnter(); | ||
var text = RunningApp.WaitForElement("timeClockOptions")[0].ReadText(); | ||
return text; | ||
} | ||
|
||
public string DateString(String format, String date) | ||
{ | ||
RunningApp.ClearText("dateFormatString"); | ||
RunningApp.EnterText("dateFormatString", format); | ||
RunningApp.PressEnter(); | ||
RunningApp.ClearText("settingDate"); | ||
RunningApp.EnterText("settingDate", date); | ||
RunningApp.PressEnter(); | ||
var text = RunningApp.WaitForElement("dateCalendarOptions")[0].ReadText(); | ||
return text; | ||
} | ||
|
||
[Test] | ||
public void TimePicker24H() | ||
{ | ||
RunningApp.Tap(x => x.Marked("TimePicker")); | ||
Assert.AreEqual("0.0.0 A", TimeString("H.m.s t", "0, 0")); | ||
Assert.AreEqual("13:05 PM", TimeString("HH:mm tt", "13, 5")); | ||
Assert.AreEqual("12 PM", TimeString("HH tt", "12, 0")); | ||
Assert.AreEqual("5.", TimeString("H.", "5, 1")); | ||
} | ||
|
||
[Test] | ||
public void TimePicker12H() | ||
{ | ||
RunningApp.Tap(x => x.Marked("TimePicker")); | ||
Assert.AreEqual("12 0/AM", TimeString("hh m/tt", "0, 0")); | ||
Assert.AreEqual("12", TimeString("hh", "12, 37")); | ||
Assert.AreEqual("11-00", TimeString("h-ss", "23, 59")); | ||
Assert.AreEqual("07:59", TimeString("hh:mm", "7, 59")); | ||
|
||
} | ||
|
||
[Test] | ||
public void TimePickerOther() | ||
{ | ||
RunningApp.Tap(x => x.Marked("TimePicker")); | ||
Assert.AreEqual("59, P", TimeString("mm, t", "13, 59")); | ||
Assert.AreEqual("ABCDEGIJLNOP", TimeString("ABCDEGIJLNOP", "23, 59")); | ||
Assert.AreEqual("QRSTUVWXYZ", TimeString("QRSTUVWXYZ", "23, 59")); | ||
Assert.AreEqual("abceijklnopqruvwx", TimeString("abceijklnopqruvwx", "23, 59")); | ||
} | ||
|
||
[Test] | ||
public void DatePickerDMY() | ||
{ | ||
RunningApp.Tap(x => x.Marked("DatePicker")); | ||
Assert.AreEqual("31/1/99", DateString("d/M/y", "1999, 1, 31")); | ||
Assert.AreEqual("02-29-00", DateString("MM-dd-yy", "2000, 2, 29")); | ||
Assert.AreEqual("2010, Apr, Thu", DateString("yyy, MMM, ddd", "2010, 4, 15")); | ||
Assert.AreEqual("August.Saturday.2015", DateString("MMMM.dddd.yyyy", "2015, 8, 1")); | ||
} | ||
|
||
[Test] | ||
public void DatePickerMissing() | ||
{ | ||
RunningApp.Tap(x => x.Marked("DatePicker")); | ||
Assert.AreEqual("October 97", DateString("MMMM yy", "1997, 10, 30")); | ||
Assert.AreEqual("Monday", DateString("dddd", "2020, 7, 20")); | ||
Assert.AreEqual("2002: Dec", DateString("yyyy: MMM", "2002, 12, 31")); | ||
} | ||
|
||
[Test] | ||
public void DatePickerLetters() | ||
{ | ||
RunningApp.Tap(x => x.Marked("DatePicker")); | ||
Assert.AreEqual("ABCDEGIJLNOP", DateString("ABCDEGIJLNOP", "2002, 12, 31")); | ||
Assert.AreEqual("QRSTUVWXYZ", DateString("QRSTUVWXYZ", "2002, 12, 31")); | ||
Assert.AreEqual("abceijklnopqruvwx", DateString("abceijklnopqruvwx", "2002, 12, 31")); | ||
} | ||
|
||
#endif | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
Xamarin.Forms.Controls/GalleryPages/DateTimePickerGalleries/DatePage.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
x:Class="Xamarin.Forms.Controls.GalleryPages.DateTimePickerGalleries.DatePage" | ||
Title="DatePicker"> | ||
<ContentPage.Content> | ||
<ScrollView> | ||
<StackLayout VerticalOptions="Center" Padding="10"> | ||
<Label Text="DatePicker Default (No Format String):" FontSize="20" FontAttributes="Bold" TextColor="#2488ad"/> | ||
<StackLayout Orientation="Horizontal" HorizontalOptions="CenterAndExpand" Margin="20"> | ||
<Label Text="DatePicker:" FontSize="18" VerticalOptions="Center"/> | ||
<DatePicker x:Name="datepickerdefault" HorizontalOptions="CenterAndExpand" MinimumWidthRequest="110"/> | ||
</StackLayout> | ||
<Label Text="DatePicker Changes With Format String:" FontSize="20" FontAttributes="Bold" TextColor="#2488ad"/> | ||
<StackLayout Orientation="Horizontal" HorizontalOptions="CenterAndExpand"> | ||
<Label Text="DatePicker:" FontSize="16" VerticalOptions="Center"/> | ||
<DatePicker x:Name="datepicker" HorizontalOptions="CenterAndExpand" WidthRequest="300" AutomationId="dateCalendarOptions"/> | ||
</StackLayout> | ||
<StackLayout Orientation="Horizontal" HorizontalOptions="CenterAndExpand"> | ||
<Label Text="Set Date (year, month, day):" FontSize="18" VerticalOptions="Center" /> | ||
<Entry x:Name="dateSetting" AutomationId="settingDate" Placeholder="enter Date " MaxLength="20" HorizontalOptions="CenterAndExpand" Completed="dateSetting_Completed"/> | ||
</StackLayout> | ||
<StackLayout Orientation="Horizontal" HorizontalOptions="CenterAndExpand"> | ||
<Label Text="Format String:" FontSize="18" VerticalOptions="Center"/> | ||
<Entry x:Name="dateformat" AutomationId="dateFormatString" Placeholder="enter Format string" MaxLength="20" Completed="dateformat_Completed" VerticalOptions="Center"/> | ||
</StackLayout> | ||
<Label x:Name="datesphoneculture" HorizontalOptions="CenterAndExpand" FontSize="18" Margin="20"/> | ||
<Label HorizontalOptions="StartAndExpand" FontSize="10" FontAttributes="Bold" TextColor="Black" Text="Format String Key:"/> | ||
<Label HorizontalOptions="StartAndExpand" FontSize="10" TextColor="Black" Text=" • M, MM = month from 1-12/01-12 | ||

 • MMM/MMMM = abbreviated/full month string | ||

 • d/dd = day from 0-31/01-31 | ||

 • ddd/dddd = abbreviated/full day of the week | ||

 • y, yy, yyy, yyyy = year with at least corresponding number of digits" /> | ||
<Label HorizontalOptions="StartAndExpand" FontSize="10" FontAttributes="Bold" TextColor="Black" Text="Some Example Format Strings:" /> | ||
<Label HorizontalOptions="StartAndExpand" FontSize="10" TextColor="Black" Text=" • MM/dd/yy | ||

 • MMMM.d.yyyy | ||

 • dd-M-yy | ||

 • MMMM dd, yyyy" /> | ||
<Label> | ||
<Label.FormattedText> | ||
<FormattedString> | ||
<Span Text="See full list of date/time format strings here" | ||
TextColor="Blue" | ||
TextDecorations="Underline" | ||
FontSize="10"> | ||
<Span.GestureRecognizers> | ||
<TapGestureRecognizer Command="{Binding TapCommand}" | ||
CommandParameter="https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings"/> | ||
</Span.GestureRecognizers> | ||
</Span> | ||
</FormattedString> | ||
</Label.FormattedText> | ||
</Label> | ||
</StackLayout> | ||
</ScrollView> | ||
</ContentPage.Content> | ||
</ContentPage> |
40 changes: 40 additions & 0 deletions
40
Xamarin.Forms.Controls/GalleryPages/DateTimePickerGalleries/DatePage.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
using Xamarin.Forms; | ||
|
||
namespace Xamarin.Forms.Controls.GalleryPages.DateTimePickerGalleries | ||
{ | ||
public partial class DatePage : ContentPage | ||
{ | ||
public DatePage() | ||
{ | ||
InitializeComponent(); | ||
BindingContext = this; | ||
var dep = DependencyService.Get<ILocalize>(); | ||
if (dep != null) | ||
{ | ||
datesphoneculture.Text = $"Device Culture: {dep.GetCurrentCultureInfo()}"; | ||
} | ||
else | ||
{ | ||
var s = System.Globalization.CultureInfo.CurrentCulture.Name; | ||
datesphoneculture.Text = "Device Culture: " + s; | ||
} | ||
} | ||
|
||
void dateformat_Completed(System.Object sender, System.EventArgs e) | ||
{ | ||
var text = ((Entry)sender).Text; | ||
datepicker.Format = text; | ||
} | ||
|
||
void dateSetting_Completed(System.Object sender, System.EventArgs e) | ||
{ | ||
var date = ((Entry)sender).Text; | ||
string[] divided = date.Split(','); | ||
int[] sep_dates = Array.ConvertAll(divided, int.Parse); | ||
datepicker.Date = new DateTime(sep_dates[0], sep_dates[1], sep_dates[2]); | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
Xamarin.Forms.Controls/GalleryPages/DateTimePickerGalleries/DateTimePickerGallery.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
xmlns:local="clr-namespace:Xamarin.Forms.Controls.GalleryPages.DateTimePickerGalleries" | ||
x:Class="Xamarin.Forms.Controls.GalleryPages.DateTimePickerGalleries.DateTimePickerGallery"> | ||
<local:DatePage AutomationId = "DateTab"/> | ||
<local:TimePage AutomationId ="TimeTab"/> | ||
<local:KeyboardPage/> | ||
</TabbedPage> |
13 changes: 13 additions & 0 deletions
13
Xamarin.Forms.Controls/GalleryPages/DateTimePickerGalleries/DateTimePickerGallery.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Xamarin.Forms.Xaml; | ||
|
||
namespace Xamarin.Forms.Controls.GalleryPages.DateTimePickerGalleries | ||
{ | ||
[XamlCompilation(XamlCompilationOptions.Compile)] | ||
public partial class DateTimePickerGallery : TabbedPage | ||
{ | ||
public DateTimePickerGallery() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
Xamarin.Forms.Controls/GalleryPages/DateTimePickerGalleries/ILocalize.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System.Globalization; | ||
namespace Xamarin.Forms.Controls.GalleryPages.DateTimePickerGalleries | ||
{ | ||
public interface ILocalize | ||
{ | ||
string GetCurrentCultureInfo(); | ||
} | ||
} | ||
|
31 changes: 31 additions & 0 deletions
31
Xamarin.Forms.Controls/GalleryPages/DateTimePickerGalleries/KeyboardPage.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
x:Class="Xamarin.Forms.Controls.GalleryPages.DateTimePickerGalleries.KeyboardPage" | ||
Title="Keyboards"> | ||
<ContentPage.Content> | ||
<ScrollView> | ||
<StackLayout VerticalOptions="Center" Padding="10"> | ||
<StackLayout Orientation="Horizontal" HorizontalOptions="CenterAndExpand"> | ||
<Label Text="Keyboard Type Picker:" FontSize="18" VerticalOptions="Center" /> | ||
<Picker x:Name="KeyboardType" HorizontalOptions="FillAndExpand" WidthRequest="100" SelectedIndexChanged="KeyboardType_SelectedIndexChanged"> | ||
<Picker.Items> | ||
<x:String>Default</x:String> | ||
<x:String>Numeric</x:String> | ||
<x:String>Plain</x:String> | ||
<x:String>Text</x:String> | ||
<x:String>Chat</x:String> | ||
<x:String>Email</x:String> | ||
<x:String>Telephone</x:String> | ||
<x:String>Url</x:String> | ||
</Picker.Items> | ||
</Picker> | ||
</StackLayout> | ||
<StackLayout Orientation="Horizontal" HorizontalOptions="CenterAndExpand"> | ||
<Label Text="Entry with Keyboard:" FontSize="18" VerticalOptions="Center" /> | ||
<Entry x:Name="keyboardEntry" Placeholder="click to see keyboard" HorizontalOptions="CenterAndExpand"/> | ||
</StackLayout> | ||
<Label x:Name="keyboardphoneculture" HorizontalOptions="CenterAndExpand" FontSize="18" Margin="20"/> | ||
</StackLayout> | ||
</ScrollView> | ||
</ContentPage.Content> | ||
</ContentPage> |
34 changes: 34 additions & 0 deletions
34
Xamarin.Forms.Controls/GalleryPages/DateTimePickerGalleries/KeyboardPage.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
using Xamarin.Forms; | ||
|
||
namespace Xamarin.Forms.Controls.GalleryPages.DateTimePickerGalleries | ||
{ | ||
public partial class KeyboardPage : ContentPage | ||
{ | ||
public KeyboardPage() | ||
{ | ||
InitializeComponent(); | ||
BindingContext = this; | ||
var dep = DependencyService.Get<ILocalize>(); | ||
if (dep != null) | ||
{ | ||
keyboardphoneculture.Text = $"Device Culture: {dep.GetCurrentCultureInfo()}"; | ||
} | ||
else | ||
{ | ||
var s = System.Globalization.CultureInfo.CurrentCulture.Name; | ||
keyboardphoneculture.Text = "Device Culture: " + s; | ||
} | ||
} | ||
|
||
void KeyboardType_SelectedIndexChanged(System.Object sender, System.EventArgs e) | ||
{ | ||
string selectedValue = KeyboardType.Items[KeyboardType.SelectedIndex]; | ||
var converter = new KeyboardTypeConverter(); | ||
string keyboardStringValue = "Keyboard." + selectedValue; | ||
keyboardEntry.Keyboard = (Keyboard)converter.ConvertFromInvariantString(keyboardStringValue); | ||
} | ||
} | ||
} |
Oops, something went wrong.