Skip to content

Commit 404b286

Browse files
[mono][HybridGlobalization] Fix ShortDatePattern year format to be "yyyy" (#99908)
* use yyyy year format for short date pattern * add test for yyyy short date pattern --------- Co-authored-by: Ilona Tomkowicz <32700855+ilonatommy@users.noreply.github.com>
1 parent 79a4daf commit 404b286

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.iOS.cs

+9
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ private bool LoadCalendarDataFromNative(string localeName, CalendarId calendarId
1818
sNativeName = GetCalendarInfoNative(localeName, calendarId, CalendarDataType.NativeName);
1919
sMonthDay = GetCalendarInfoNative(localeName, calendarId, CalendarDataType.MonthDay);
2020
saShortDates = GetCalendarInfoNative(localeName, calendarId, CalendarDataType.ShortDates).Split("||");
21+
// Handle ShortDatePattern to have "yyyy" year format
22+
List<string> shortDatePatternList = new List<string>(saShortDates);
23+
for (int i = 0; i < shortDatePatternList.Count; i++)
24+
{
25+
shortDatePatternList[i] = NormalizeDatePattern(shortDatePatternList[i]);
26+
}
27+
FixDefaultShortDatePattern(shortDatePatternList);
28+
saShortDates = shortDatePatternList.ToArray();
29+
2130
saLongDates = GetCalendarInfoNative(localeName, calendarId, CalendarDataType.LongDates).Split("||");
2231
saYearMonths = GetCalendarInfoNative(localeName, calendarId, CalendarDataType.YearMonths).Split("||");
2332
saDayNames = GetCalendarInfoNative(localeName, calendarId, CalendarDataType.DayNames).Split("||");

src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoShortDatePattern.cs

+13-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ namespace System.Globalization.Tests
88
{
99
public class DateTimeFormatInfoShortDatePattern
1010
{
11+
public static IEnumerable<object[]> ShortDatePattern_Get_TestData()
12+
{
13+
yield return new object[] { DateTimeFormatInfo.InvariantInfo, "MM/dd/yyyy", "invariant" };
14+
yield return new object[] { new CultureInfo("en-US").DateTimeFormat, "M/d/yyyy", "en-US" };
15+
yield return new object[] { new CultureInfo("fr-FR").DateTimeFormat, "dd/MM/yyyy", "fr-FR" };
16+
}
1117
public static IEnumerable<object[]> ShortDatePattern_Get_TestData_HybridGlobalization()
1218
{
1319
// see the comments on the right to check the non-Hybrid result, if it differs
@@ -131,7 +137,6 @@ public static IEnumerable<object[]> ShortDatePattern_Get_TestData_HybridGlobaliz
131137
yield return new object[] { "en-ZA", "yyyy/MM/dd" };
132138
yield return new object[] { "en-ZM", "dd/MM/yyyy" };
133139
yield return new object[] { "en-ZW", "d/M/yyyy" };
134-
yield return new object[] { "en-US", "M/d/yyyy" };
135140
yield return new object[] { "es-419", "d/M/yyyy" };
136141
yield return new object[] { "es-ES", "d/M/yyyy" };
137142
yield return new object[] { "es-MX", "dd/MM/yyyy" };
@@ -200,6 +205,13 @@ public static IEnumerable<object[]> ShortDatePattern_Get_TestData_HybridGlobaliz
200205
yield return new object[] { "zh-TW", "yyyy/M/d" };
201206
}
202207

208+
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsHybridGlobalizationOnApplePlatform))]
209+
[MemberData(nameof(ShortDatePattern_Get_TestData))]
210+
public void ShortDatePattern_Get_ReturnsExpected(DateTimeFormatInfo format, string expected, string cultureName)
211+
{
212+
Assert.True(expected == format.ShortDatePattern, $"Failed for culture: {cultureName}. Expected: {expected}, Actual: {format.ShortDatePattern}");
213+
}
214+
203215
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsHybridGlobalizationOnBrowser))]
204216
[MemberData(nameof(ShortDatePattern_Get_TestData_HybridGlobalization))]
205217
public void ShortDatePattern_Get_ReturnsExpected_HybridGlobalization(string cultureName, string expected)

0 commit comments

Comments
 (0)