From e2ac11214ec22de16b6efc0476dce91b5d909281 Mon Sep 17 00:00:00 2001 From: Matous Kozak Date: Mon, 18 Mar 2024 15:44:58 +0100 Subject: [PATCH 1/8] use yyyy year format for short date pattern --- .../libs/System.Globalization.Native/pal_calendarData.m | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/native/libs/System.Globalization.Native/pal_calendarData.m b/src/native/libs/System.Globalization.Native/pal_calendarData.m index 9520e17646754..7289dc239089f 100644 --- a/src/native/libs/System.Globalization.Native/pal_calendarData.m +++ b/src/native/libs/System.Globalization.Native/pal_calendarData.m @@ -118,6 +118,12 @@ static CalendarId GetCalendarId(const char* calendarName) { [dateFormat setDateStyle:NSDateFormatterShortStyle]; NSString *shortFormatString = [dateFormat dateFormat]; + // Replace the year format with a 4-digit year format + if ([shortFormatString rangeOfString:@"yy"].location != NSNotFound) { + shortFormatString = [shortFormatString stringByReplacingOccurrencesOfString:@"yy" withString:@"yyyy"]; + } else if ([shortFormatString rangeOfString:@"y"].location != NSNotFound) { + shortFormatString = [shortFormatString stringByReplacingOccurrencesOfString:@"y" withString:@"yyyy"]; + } [dateFormat setDateStyle:NSDateFormatterMediumStyle]; NSString *mediumFormatString = [dateFormat dateFormat]; NSString *yearMonthDayFormat = [NSDateFormatter dateFormatFromTemplate:@"yMd" options:0 locale:currentLocale]; From bac07687f019630628d3ee66c62b9649f5cfcc5d Mon Sep 17 00:00:00 2001 From: Matous Kozak Date: Mon, 18 Mar 2024 15:45:39 +0100 Subject: [PATCH 2/8] add test for yyyy short date pattern --- .../DateTimeFormatInfoShortDatePattern.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoShortDatePattern.cs b/src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoShortDatePattern.cs index dd601d0f9ffb9..7d6c6ae455df0 100644 --- a/src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoShortDatePattern.cs +++ b/src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoShortDatePattern.cs @@ -232,6 +232,21 @@ public void ShortDatePattern_Set_GetReturnsExpected(string value) Assert.Equal(value, format.ShortDatePattern); } + public static IEnumerable ShortDatePatter_Set_Culture_TestData() + { + yield return new object[] { "de-DE", "dd.MM.yyyy" }; + yield return new object[] { "en-US", "M/d/yyyy" }; + yield return new object[] { "fa-IR", "yyyy/M/d" }; + } + + [Theory] + [MemberData(nameof(ShortDatePatter_Set_Culture_TestData))] + public void ShortDatePattern_SetCulture_GetReturnsExpected(string cultureName, string expected) + { + var format = new CultureInfo(cultureName).DateTimeFormat; + Assert.True(expected == format.ShortDatePattern, $"Failed for culture: {cultureName}. Expected: {expected}, Actual: {format.ShortDatePattern}"); + } + [Fact] public void ShortDatePattern_Set_InvalidatesDerivedPatterns() { From cac9179c063e76753d031fd2f18cce0b14fcc1fa Mon Sep 17 00:00:00 2001 From: Matous Kozak Date: Tue, 19 Mar 2024 12:08:07 +0100 Subject: [PATCH 3/8] Revert "add test for yyyy short date pattern" This reverts commit bac07687f019630628d3ee66c62b9649f5cfcc5d. --- .../DateTimeFormatInfoShortDatePattern.cs | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoShortDatePattern.cs b/src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoShortDatePattern.cs index 7d6c6ae455df0..dd601d0f9ffb9 100644 --- a/src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoShortDatePattern.cs +++ b/src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoShortDatePattern.cs @@ -232,21 +232,6 @@ public void ShortDatePattern_Set_GetReturnsExpected(string value) Assert.Equal(value, format.ShortDatePattern); } - public static IEnumerable ShortDatePatter_Set_Culture_TestData() - { - yield return new object[] { "de-DE", "dd.MM.yyyy" }; - yield return new object[] { "en-US", "M/d/yyyy" }; - yield return new object[] { "fa-IR", "yyyy/M/d" }; - } - - [Theory] - [MemberData(nameof(ShortDatePatter_Set_Culture_TestData))] - public void ShortDatePattern_SetCulture_GetReturnsExpected(string cultureName, string expected) - { - var format = new CultureInfo(cultureName).DateTimeFormat; - Assert.True(expected == format.ShortDatePattern, $"Failed for culture: {cultureName}. Expected: {expected}, Actual: {format.ShortDatePattern}"); - } - [Fact] public void ShortDatePattern_Set_InvalidatesDerivedPatterns() { From 99d7ea3129383014c7b4121c310d986ab8e45004 Mon Sep 17 00:00:00 2001 From: Matous Kozak Date: Tue, 19 Mar 2024 13:43:01 +0100 Subject: [PATCH 4/8] enable short date year format tests for Apple HG --- .../DateTimeFormatInfoShortDatePattern.cs | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoShortDatePattern.cs b/src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoShortDatePattern.cs index dd601d0f9ffb9..f83557fbef047 100644 --- a/src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoShortDatePattern.cs +++ b/src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoShortDatePattern.cs @@ -11,9 +11,9 @@ public class DateTimeFormatInfoShortDatePattern public static IEnumerable ShortDatePattern_Get_TestData_HybridGlobalization() { // see the comments on the right to check the non-Hybrid result, if it differs - yield return new object[] { "ar-SA", "d\u200f/M\u200f/yyyy" }; // "d\u200f/M\u200f/yyyy g" + yield return new object[] { "ar-SA", PlatformDetection.IsHybridGlobalizationOnBrowser ? "d\u200f/M\u200f/yyyy" : "d MMM، yyyy G" }; // "d\u200f/M\u200f/yyyy g" yield return new object[] { "am-ET", "dd/MM/yyyy" }; - yield return new object[] { "bg-BG", "d.MM.yyyy г." }; // "d.MM.yyyy 'г'." + yield return new object[] { "bg-BG", PlatformDetection.IsHybridGlobalizationOnBrowser ? "d.MM.yyyy г." : "d.MM.yyyy 'г'." }; // "d.MM.yyyy 'г'." yield return new object[] { "bn-BD", "d/M/yyyy" }; yield return new object[] { "bn-IN", "d/M/yyyy" }; yield return new object[] { "ca-AD", "d/M/yyyy" }; @@ -33,7 +33,7 @@ public static IEnumerable ShortDatePattern_Get_TestData_HybridGlobaliz yield return new object[] { "en-AG", "dd/MM/yyyy" }; yield return new object[] { "en-AI", "dd/MM/yyyy" }; yield return new object[] { "en-AS", "M/d/yyyy" }; - yield return new object[] { "en-AT", "dd/MM/yyyy" }; + yield return new object[] { "en-AT", PlatformDetection.IsHybridGlobalizationOnBrowser ? "dd/MM/yyyy" : "dd.MM.yyyy" }; // "dd/MM/yyyy" yield return new object[] { "en-AU", "d/M/yyyy" }; yield return new object[] { "en-BB", "dd/MM/yyyy" }; yield return new object[] { "en-BE", "dd/MM/yyyy" }; @@ -49,11 +49,11 @@ public static IEnumerable ShortDatePattern_Get_TestData_HybridGlobaliz yield return new object[] { "en-CM", "dd/MM/yyyy" }; yield return new object[] { "en-CX", "dd/MM/yyyy" }; yield return new object[] { "en-CY", "dd/MM/yyyy" }; - yield return new object[] { "en-DE", "dd/MM/yyyy" }; + yield return new object[] { "en-DE", PlatformDetection.IsHybridGlobalizationOnBrowser ? "dd/MM/yyyy" : "dd.MM.yyyy" }; // "dd/MM/yyyy" yield return new object[] { "en-DK", "dd/MM/yyyy" }; yield return new object[] { "en-DM", "dd/MM/yyyy" }; yield return new object[] { "en-ER", "dd/MM/yyyy" }; - yield return new object[] { "en-FI", "dd/MM/yyyy" }; + yield return new object[] { "en-FI", PlatformDetection.IsHybridGlobalizationOnBrowser ? "dd/MM/yyyy" : "d.M.yyyy" }; // "dd/MM/yyyy" yield return new object[] { "en-FJ", "dd/MM/yyyy" }; yield return new object[] { "en-FK", "dd/MM/yyyy" }; yield return new object[] { "en-FM", "dd/MM/yyyy" }; @@ -95,7 +95,7 @@ public static IEnumerable ShortDatePattern_Get_TestData_HybridGlobaliz yield return new object[] { "en-NL", "dd/MM/yyyy" }; yield return new object[] { "en-NR", "dd/MM/yyyy" }; yield return new object[] { "en-NU", "dd/MM/yyyy" }; - yield return new object[] { "en-NZ", "d/MM/yyyy" }; + yield return new object[] { "en-NZ", PlatformDetection.IsHybridGlobalizationOnBrowser ? "d/MM/yyyy" : "dd/MM/yyyy" }; // "d/MM/yyyy" yield return new object[] { "en-PG", "dd/MM/yyyy" }; yield return new object[] { "en-PH", "M/d/yyyy" }; // "dd/MM/yyyy" yield return new object[] { "en-PK", "dd/MM/yyyy" }; @@ -109,7 +109,7 @@ public static IEnumerable ShortDatePattern_Get_TestData_HybridGlobaliz yield return new object[] { "en-SE", "yyyy-MM-dd" }; yield return new object[] { "en-SG", "d/M/yyyy" }; yield return new object[] { "en-SH", "dd/MM/yyyy" }; - yield return new object[] { "en-SI", "dd/MM/yyyy" }; + yield return new object[] { "en-SI", PlatformDetection.IsHybridGlobalizationOnBrowser ? "dd/MM/yyyy" : "d. M. yyyy" }; // "dd/MM/yyyy" yield return new object[] { "en-SL", "dd/MM/yyyy" }; yield return new object[] { "en-SS", "dd/MM/yyyy" }; yield return new object[] { "en-SX", "dd/MM/yyyy" }; @@ -147,7 +147,7 @@ public static IEnumerable ShortDatePattern_Get_TestData_HybridGlobaliz yield return new object[] { "he-IL", "d.M.yyyy" }; yield return new object[] { "hi-IN", "d/M/yyyy" }; yield return new object[] { "hr-BA", "d. M. yyyy." }; - yield return new object[] { "hr-HR", "dd. MM. yyyy." }; + yield return new object[] { "hr-HR", PlatformDetection.IsHybridGlobalizationOnBrowser ? "dd. MM. yyyy." : "dd.MM.yyyy." }; // "dd. MM. yyyy." yield return new object[] { "hu-HU", "yyyy. MM. dd." }; yield return new object[] { "id-ID", "dd/MM/yyyy" }; yield return new object[] { "it-CH", "dd.MM.yyyy" }; @@ -173,8 +173,8 @@ public static IEnumerable ShortDatePattern_Get_TestData_HybridGlobaliz yield return new object[] { "pt-PT", "dd/MM/yyyy" }; yield return new object[] { "ro-RO", "dd.MM.yyyy" }; yield return new object[] { "ru-RU", "dd.MM.yyyy" }; - yield return new object[] { "sk-SK", "d. M. yyyy" }; - yield return new object[] { "sl-SI", "d. MM. yyyy" }; + yield return new object[] { "sk-SK", PlatformDetection.IsHybridGlobalizationOnBrowser ? "d. M. yyyy" : "d.M.yyyy" }; // "d. M. yyyy" + yield return new object[] { "sl-SI", PlatformDetection.IsHybridGlobalizationOnBrowser ? "d. MM. yyyy" : "d. M. yyyy" }; // "d. MM. yyyy" yield return new object[] { "sr-Cyrl-RS", "d.M.yyyy." }; yield return new object[] { "sr-Latn-RS", "d.M.yyyy." }; yield return new object[] { "sv-AX", "yyyy-MM-dd" }; @@ -192,7 +192,7 @@ public static IEnumerable ShortDatePattern_Get_TestData_HybridGlobaliz yield return new object[] { "tr-CY", "d.MM.yyyy" }; yield return new object[] { "tr-TR", "d.MM.yyyy" }; yield return new object[] { "uk-UA", "dd.MM.yyyy" }; - yield return new object[] { "vi-VN", "dd/MM/yyyy" }; + yield return new object[] { "vi-VN", PlatformDetection.IsHybridGlobalizationOnBrowser ? "dd/MM/yyyy" : "d/M/yyyy" }; // "dd/MM/yyyy" yield return new object[] { "zh-CN", "yyyy/M/d" }; yield return new object[] { "zh-Hans-HK", "d/M/yyyy" }; yield return new object[] { "zh-SG", "dd/MM/yyyy" }; @@ -200,7 +200,7 @@ public static IEnumerable ShortDatePattern_Get_TestData_HybridGlobaliz yield return new object[] { "zh-TW", "yyyy/M/d" }; } - [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsHybridGlobalizationOnBrowser))] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsHybridGlobalization))] [MemberData(nameof(ShortDatePattern_Get_TestData_HybridGlobalization))] public void ShortDatePattern_Get_ReturnsExpected_HybridGlobalization(string cultureName, string expected) { From 45d338ad8512748e60909449e1a8eaf9d5c02509 Mon Sep 17 00:00:00 2001 From: Matous Kozak Date: Tue, 19 Mar 2024 17:15:44 +0100 Subject: [PATCH 5/8] do not modify other than y and yy year formats --- .../pal_calendarData.m | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/native/libs/System.Globalization.Native/pal_calendarData.m b/src/native/libs/System.Globalization.Native/pal_calendarData.m index 7289dc239089f..94b72dbcc3b34 100644 --- a/src/native/libs/System.Globalization.Native/pal_calendarData.m +++ b/src/native/libs/System.Globalization.Native/pal_calendarData.m @@ -118,12 +118,26 @@ static CalendarId GetCalendarId(const char* calendarName) { [dateFormat setDateStyle:NSDateFormatterShortStyle]; NSString *shortFormatString = [dateFormat dateFormat]; - // Replace the year format with a 4-digit year format - if ([shortFormatString rangeOfString:@"yy"].location != NSNotFound) { - shortFormatString = [shortFormatString stringByReplacingOccurrencesOfString:@"yy" withString:@"yyyy"]; - } else if ([shortFormatString rangeOfString:@"y"].location != NSNotFound) { - shortFormatString = [shortFormatString stringByReplacingOccurrencesOfString:@"y" withString:@"yyyy"]; - } + // Replace "y" and "yy" year format with a 4-digit year format + NSRange range = [shortFormatString rangeOfString:@"y"]; + if (range.location != NSNotFound) + { + int length = [shortFormatString length]; + if (range.location + 2 < length && [shortFormatString characterAtIndex:range.location + 1] == 'y' && [shortFormatString characterAtIndex:range.location + 2] == 'y') + { + // Not "y" or "yy" year format + ; + } else if (range.location + 1 < length && [shortFormatString characterAtIndex:range.location + 1] == 'y') // "yy" + { + range.length = 2; + shortFormatString = [shortFormatString stringByReplacingCharactersInRange:range withString:@"yyyy"]; + } + else // "y" + { + range.length = 1; + shortFormatString = [shortFormatString stringByReplacingCharactersInRange:range withString:@"yyyy"]; + } + } [dateFormat setDateStyle:NSDateFormatterMediumStyle]; NSString *mediumFormatString = [dateFormat dateFormat]; NSString *yearMonthDayFormat = [NSDateFormatter dateFormatFromTemplate:@"yMd" options:0 locale:currentLocale]; From 08a407d82ed82a066db8f46ae29d4b6636e13901 Mon Sep 17 00:00:00 2001 From: Matous Kozak Date: Mon, 25 Mar 2024 17:28:19 +0100 Subject: [PATCH 6/8] fix formating of short date year pattern for Apple --- .../System/Globalization/CalendarData.iOS.cs | 9 +++++++++ .../DateTimeFormatInfoShortDatePattern.cs | 2 +- .../pal_calendarData.m | 20 ------------------- 3 files changed, 10 insertions(+), 21 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.iOS.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.iOS.cs index 6ebd6a2964d45..b0ccc60ac5e1b 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.iOS.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.iOS.cs @@ -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 shortDatePatternList = new List(saShortDates); + for (int i = 0; i < shortDatePatternList.Count; i++) + { + shortDatePatternList[i] = NormalizeDatePattern(shortDatePatternList[i]); + } + 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("||"); diff --git a/src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoShortDatePattern.cs b/src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoShortDatePattern.cs index f83557fbef047..f163d296a887a 100644 --- a/src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoShortDatePattern.cs +++ b/src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoShortDatePattern.cs @@ -11,7 +11,7 @@ public class DateTimeFormatInfoShortDatePattern public static IEnumerable ShortDatePattern_Get_TestData_HybridGlobalization() { // see the comments on the right to check the non-Hybrid result, if it differs - yield return new object[] { "ar-SA", PlatformDetection.IsHybridGlobalizationOnBrowser ? "d\u200f/M\u200f/yyyy" : "d MMM، yyyy G" }; // "d\u200f/M\u200f/yyyy g" + yield return new object[] { "ar-SA", PlatformDetection.IsHybridGlobalizationOnBrowser ? "d\u200f/M\u200f/yyyy" : "d MMM، yyyy g" }; // "d\u200f/M\u200f/yyyy g" yield return new object[] { "am-ET", "dd/MM/yyyy" }; yield return new object[] { "bg-BG", PlatformDetection.IsHybridGlobalizationOnBrowser ? "d.MM.yyyy г." : "d.MM.yyyy 'г'." }; // "d.MM.yyyy 'г'." yield return new object[] { "bn-BD", "d/M/yyyy" }; diff --git a/src/native/libs/System.Globalization.Native/pal_calendarData.m b/src/native/libs/System.Globalization.Native/pal_calendarData.m index 94b72dbcc3b34..9520e17646754 100644 --- a/src/native/libs/System.Globalization.Native/pal_calendarData.m +++ b/src/native/libs/System.Globalization.Native/pal_calendarData.m @@ -118,26 +118,6 @@ static CalendarId GetCalendarId(const char* calendarName) { [dateFormat setDateStyle:NSDateFormatterShortStyle]; NSString *shortFormatString = [dateFormat dateFormat]; - // Replace "y" and "yy" year format with a 4-digit year format - NSRange range = [shortFormatString rangeOfString:@"y"]; - if (range.location != NSNotFound) - { - int length = [shortFormatString length]; - if (range.location + 2 < length && [shortFormatString characterAtIndex:range.location + 1] == 'y' && [shortFormatString characterAtIndex:range.location + 2] == 'y') - { - // Not "y" or "yy" year format - ; - } else if (range.location + 1 < length && [shortFormatString characterAtIndex:range.location + 1] == 'y') // "yy" - { - range.length = 2; - shortFormatString = [shortFormatString stringByReplacingCharactersInRange:range withString:@"yyyy"]; - } - else // "y" - { - range.length = 1; - shortFormatString = [shortFormatString stringByReplacingCharactersInRange:range withString:@"yyyy"]; - } - } [dateFormat setDateStyle:NSDateFormatterMediumStyle]; NSString *mediumFormatString = [dateFormat dateFormat]; NSString *yearMonthDayFormat = [NSDateFormatter dateFormatFromTemplate:@"yMd" options:0 locale:currentLocale]; From b691f4da728353d9eb4c05e614529976934f2604 Mon Sep 17 00:00:00 2001 From: Matous Kozak <55735845+matouskozak@users.noreply.github.com> Date: Wed, 27 Mar 2024 12:02:47 +0100 Subject: [PATCH 7/8] Update src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoShortDatePattern.cs Co-authored-by: Ilona Tomkowicz <32700855+ilonatommy@users.noreply.github.com> --- .../DateTimeFormatInfo/DateTimeFormatInfoShortDatePattern.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoShortDatePattern.cs b/src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoShortDatePattern.cs index f163d296a887a..6933f479e07ae 100644 --- a/src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoShortDatePattern.cs +++ b/src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoShortDatePattern.cs @@ -11,7 +11,7 @@ public class DateTimeFormatInfoShortDatePattern public static IEnumerable ShortDatePattern_Get_TestData_HybridGlobalization() { // see the comments on the right to check the non-Hybrid result, if it differs - yield return new object[] { "ar-SA", PlatformDetection.IsHybridGlobalizationOnBrowser ? "d\u200f/M\u200f/yyyy" : "d MMM، yyyy g" }; // "d\u200f/M\u200f/yyyy g" + yield return new object[] { "ar-SA", PlatformDetection.IsHybridGlobalizationOnBrowser ? "d\u200f/M\u200f/yyyy" : "d MMM\u060c yyyy g" }; // "d\u200f/M\u200f/yyyy g" yield return new object[] { "am-ET", "dd/MM/yyyy" }; yield return new object[] { "bg-BG", PlatformDetection.IsHybridGlobalizationOnBrowser ? "d.MM.yyyy г." : "d.MM.yyyy 'г'." }; // "d.MM.yyyy 'г'." yield return new object[] { "bn-BD", "d/M/yyyy" }; From 71898da0dfa8836936d4ba05e35683b2c9ebf35a Mon Sep 17 00:00:00 2001 From: Matous Kozak Date: Sat, 30 Mar 2024 19:50:53 +0100 Subject: [PATCH 8/8] reduce tests to a stable subset of locales --- .../DateTimeFormatInfoShortDatePattern.cs | 38 ++++++++++++------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoShortDatePattern.cs b/src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoShortDatePattern.cs index 6933f479e07ae..089640f0ccfcc 100644 --- a/src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoShortDatePattern.cs +++ b/src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoShortDatePattern.cs @@ -8,12 +8,18 @@ namespace System.Globalization.Tests { public class DateTimeFormatInfoShortDatePattern { + public static IEnumerable 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 ShortDatePattern_Get_TestData_HybridGlobalization() { // see the comments on the right to check the non-Hybrid result, if it differs - yield return new object[] { "ar-SA", PlatformDetection.IsHybridGlobalizationOnBrowser ? "d\u200f/M\u200f/yyyy" : "d MMM\u060c yyyy g" }; // "d\u200f/M\u200f/yyyy g" + yield return new object[] { "ar-SA", "d\u200f/M\u200f/yyyy" }; // "d\u200f/M\u200f/yyyy g" yield return new object[] { "am-ET", "dd/MM/yyyy" }; - yield return new object[] { "bg-BG", PlatformDetection.IsHybridGlobalizationOnBrowser ? "d.MM.yyyy г." : "d.MM.yyyy 'г'." }; // "d.MM.yyyy 'г'." + yield return new object[] { "bg-BG", "d.MM.yyyy г." }; // "d.MM.yyyy 'г'." yield return new object[] { "bn-BD", "d/M/yyyy" }; yield return new object[] { "bn-IN", "d/M/yyyy" }; yield return new object[] { "ca-AD", "d/M/yyyy" }; @@ -33,7 +39,7 @@ public static IEnumerable ShortDatePattern_Get_TestData_HybridGlobaliz yield return new object[] { "en-AG", "dd/MM/yyyy" }; yield return new object[] { "en-AI", "dd/MM/yyyy" }; yield return new object[] { "en-AS", "M/d/yyyy" }; - yield return new object[] { "en-AT", PlatformDetection.IsHybridGlobalizationOnBrowser ? "dd/MM/yyyy" : "dd.MM.yyyy" }; // "dd/MM/yyyy" + yield return new object[] { "en-AT", "dd/MM/yyyy" }; yield return new object[] { "en-AU", "d/M/yyyy" }; yield return new object[] { "en-BB", "dd/MM/yyyy" }; yield return new object[] { "en-BE", "dd/MM/yyyy" }; @@ -49,11 +55,11 @@ public static IEnumerable ShortDatePattern_Get_TestData_HybridGlobaliz yield return new object[] { "en-CM", "dd/MM/yyyy" }; yield return new object[] { "en-CX", "dd/MM/yyyy" }; yield return new object[] { "en-CY", "dd/MM/yyyy" }; - yield return new object[] { "en-DE", PlatformDetection.IsHybridGlobalizationOnBrowser ? "dd/MM/yyyy" : "dd.MM.yyyy" }; // "dd/MM/yyyy" + yield return new object[] { "en-DE", "dd/MM/yyyy" }; yield return new object[] { "en-DK", "dd/MM/yyyy" }; yield return new object[] { "en-DM", "dd/MM/yyyy" }; yield return new object[] { "en-ER", "dd/MM/yyyy" }; - yield return new object[] { "en-FI", PlatformDetection.IsHybridGlobalizationOnBrowser ? "dd/MM/yyyy" : "d.M.yyyy" }; // "dd/MM/yyyy" + yield return new object[] { "en-FI", "dd/MM/yyyy" }; yield return new object[] { "en-FJ", "dd/MM/yyyy" }; yield return new object[] { "en-FK", "dd/MM/yyyy" }; yield return new object[] { "en-FM", "dd/MM/yyyy" }; @@ -95,7 +101,7 @@ public static IEnumerable ShortDatePattern_Get_TestData_HybridGlobaliz yield return new object[] { "en-NL", "dd/MM/yyyy" }; yield return new object[] { "en-NR", "dd/MM/yyyy" }; yield return new object[] { "en-NU", "dd/MM/yyyy" }; - yield return new object[] { "en-NZ", PlatformDetection.IsHybridGlobalizationOnBrowser ? "d/MM/yyyy" : "dd/MM/yyyy" }; // "d/MM/yyyy" + yield return new object[] { "en-NZ", "d/MM/yyyy" }; yield return new object[] { "en-PG", "dd/MM/yyyy" }; yield return new object[] { "en-PH", "M/d/yyyy" }; // "dd/MM/yyyy" yield return new object[] { "en-PK", "dd/MM/yyyy" }; @@ -109,7 +115,7 @@ public static IEnumerable ShortDatePattern_Get_TestData_HybridGlobaliz yield return new object[] { "en-SE", "yyyy-MM-dd" }; yield return new object[] { "en-SG", "d/M/yyyy" }; yield return new object[] { "en-SH", "dd/MM/yyyy" }; - yield return new object[] { "en-SI", PlatformDetection.IsHybridGlobalizationOnBrowser ? "dd/MM/yyyy" : "d. M. yyyy" }; // "dd/MM/yyyy" + yield return new object[] { "en-SI", "dd/MM/yyyy" }; yield return new object[] { "en-SL", "dd/MM/yyyy" }; yield return new object[] { "en-SS", "dd/MM/yyyy" }; yield return new object[] { "en-SX", "dd/MM/yyyy" }; @@ -131,7 +137,6 @@ public static IEnumerable 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" }; 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" }; @@ -147,7 +152,7 @@ public static IEnumerable ShortDatePattern_Get_TestData_HybridGlobaliz yield return new object[] { "he-IL", "d.M.yyyy" }; yield return new object[] { "hi-IN", "d/M/yyyy" }; yield return new object[] { "hr-BA", "d. M. yyyy." }; - yield return new object[] { "hr-HR", PlatformDetection.IsHybridGlobalizationOnBrowser ? "dd. MM. yyyy." : "dd.MM.yyyy." }; // "dd. MM. yyyy." + yield return new object[] { "hr-HR", "dd. MM. yyyy." }; yield return new object[] { "hu-HU", "yyyy. MM. dd." }; yield return new object[] { "id-ID", "dd/MM/yyyy" }; yield return new object[] { "it-CH", "dd.MM.yyyy" }; @@ -173,8 +178,8 @@ public static IEnumerable ShortDatePattern_Get_TestData_HybridGlobaliz yield return new object[] { "pt-PT", "dd/MM/yyyy" }; yield return new object[] { "ro-RO", "dd.MM.yyyy" }; yield return new object[] { "ru-RU", "dd.MM.yyyy" }; - yield return new object[] { "sk-SK", PlatformDetection.IsHybridGlobalizationOnBrowser ? "d. M. yyyy" : "d.M.yyyy" }; // "d. M. yyyy" - yield return new object[] { "sl-SI", PlatformDetection.IsHybridGlobalizationOnBrowser ? "d. MM. yyyy" : "d. M. yyyy" }; // "d. MM. yyyy" + yield return new object[] { "sk-SK", "d. M. yyyy" }; + yield return new object[] { "sl-SI", "d. MM. yyyy" }; yield return new object[] { "sr-Cyrl-RS", "d.M.yyyy." }; yield return new object[] { "sr-Latn-RS", "d.M.yyyy." }; yield return new object[] { "sv-AX", "yyyy-MM-dd" }; @@ -192,7 +197,7 @@ public static IEnumerable ShortDatePattern_Get_TestData_HybridGlobaliz yield return new object[] { "tr-CY", "d.MM.yyyy" }; yield return new object[] { "tr-TR", "d.MM.yyyy" }; yield return new object[] { "uk-UA", "dd.MM.yyyy" }; - yield return new object[] { "vi-VN", PlatformDetection.IsHybridGlobalizationOnBrowser ? "dd/MM/yyyy" : "d/M/yyyy" }; // "dd/MM/yyyy" + yield return new object[] { "vi-VN", "dd/MM/yyyy" }; yield return new object[] { "zh-CN", "yyyy/M/d" }; yield return new object[] { "zh-Hans-HK", "d/M/yyyy" }; yield return new object[] { "zh-SG", "dd/MM/yyyy" }; @@ -200,7 +205,14 @@ public static IEnumerable ShortDatePattern_Get_TestData_HybridGlobaliz yield return new object[] { "zh-TW", "yyyy/M/d" }; } - [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsHybridGlobalization))] + [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) {