Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mono][HybridGlobalization] Fix ShortDatePattern year format to be "yyyy" #99908

Merged
merged 11 commits into from
Apr 9, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ private bool LoadCalendarDataFromNative(string localeName, CalendarId calendarId
sNativeName = GetCalendarInfoNative(localeName, calendarId, CalendarDataType.NativeName);
sMonthDay = GetCalendarInfoNative(localeName, calendarId, CalendarDataType.MonthDay);
saShortDates = GetCalendarInfoNative(localeName, calendarId, CalendarDataType.ShortDates).Split("||");
// Handle ShortDatePattern to have "yyyy" year format
List<string> shortDatePatternList = new List<string>(saShortDates);
for (int i = 0; i < shortDatePatternList.Count; i++)
{
shortDatePatternList[i] = NormalizeDatePattern(shortDatePatternList[i]);
ilonatommy marked this conversation as resolved.
Show resolved Hide resolved
}
FixDefaultShortDatePattern(shortDatePatternList);
saShortDates = shortDatePatternList.ToArray();

saLongDates = GetCalendarInfoNative(localeName, calendarId, CalendarDataType.LongDates).Split("||");
saYearMonths = GetCalendarInfoNative(localeName, calendarId, CalendarDataType.YearMonths).Split("||");
saDayNames = GetCalendarInfoNative(localeName, calendarId, CalendarDataType.DayNames).Split("||");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ namespace System.Globalization.Tests
{
public class DateTimeFormatInfoShortDatePattern
{
public static IEnumerable<object[]> ShortDatePattern_Get_TestData()
{
yield return new object[] { DateTimeFormatInfo.InvariantInfo, "MM/dd/yyyy", "invariant" };
yield return new object[] { new CultureInfo("en-US").DateTimeFormat, "M/d/yyyy", "en-US" };
yield return new object[] { new CultureInfo("fr-FR").DateTimeFormat, "dd/MM/yyyy", "fr-FR" };
}
public static IEnumerable<object[]> ShortDatePattern_Get_TestData_HybridGlobalization()
{
// see the comments on the right to check the non-Hybrid result, if it differs
Expand Down Expand Up @@ -131,7 +137,6 @@ public static IEnumerable<object[]> ShortDatePattern_Get_TestData_HybridGlobaliz
yield return new object[] { "en-ZA", "yyyy/MM/dd" };
yield return new object[] { "en-ZM", "dd/MM/yyyy" };
yield return new object[] { "en-ZW", "d/M/yyyy" };
yield return new object[] { "en-US", "M/d/yyyy" };
matouskozak marked this conversation as resolved.
Show resolved Hide resolved
yield return new object[] { "es-419", "d/M/yyyy" };
yield return new object[] { "es-ES", "d/M/yyyy" };
yield return new object[] { "es-MX", "dd/MM/yyyy" };
Expand Down Expand Up @@ -200,6 +205,13 @@ public static IEnumerable<object[]> ShortDatePattern_Get_TestData_HybridGlobaliz
yield return new object[] { "zh-TW", "yyyy/M/d" };
}

[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsHybridGlobalizationOnApplePlatform))]
[MemberData(nameof(ShortDatePattern_Get_TestData))]
public void ShortDatePattern_Get_ReturnsExpected(DateTimeFormatInfo format, string expected, string cultureName)
{
Assert.True(expected == format.ShortDatePattern, $"Failed for culture: {cultureName}. Expected: {expected}, Actual: {format.ShortDatePattern}");
}

[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsHybridGlobalizationOnBrowser))]
[MemberData(nameof(ShortDatePattern_Get_TestData_HybridGlobalization))]
public void ShortDatePattern_Get_ReturnsExpected_HybridGlobalization(string cultureName, string expected)
Expand Down
Loading