- Notifications
You must be signed in to change notification settings - Fork5.2k
Fix the ICU time format conversion logic#103681
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Fix the ICU time format conversion logic#103681
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Revise the ICU time format conversion logic to support all unquoted literal texts and the `B` and `b` pattern symbols.Fixdotnet#103592
PopSlime commentedJun 19, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I'm new to such a big and complex project and not sure how to test these changes, so this is a draft at the moment. Looking forward to help from anyone. Example affected patterns:
More information can be found in the fixing issue. |
mkhamoyan commentedJun 19, 2024
@PopSlime thanks for submitting the PR. |
mkhamoyan commentedJun 19, 2024
/azp run runtime-extra-platforms |
| Azure Pipelines successfully started running 1 pipeline(s). |
PopSlime commentedJun 19, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@mkhamoyan I'm not sure how to write the test for this because the retrieved time format is device-/platform-dependent. Instead of testing against some specific patterns, I'm considering adding a test that fails if a 12-hour clock is used without an AM/PM designator in any pattern in any culture. Also we need another test for the unquoted literal texts, which I have no clues how to do yet. By the way, short time patterns are also affected by this PR. |
mkhamoyan commentedJun 19, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@PopSlime I was thinking something like below (same test case for shorttime patterns underhere) would validate the change. This should be consistent for all platforms and devices. |
PopSlime commentedJun 19, 2024
@mkhamoyan Is it safe to assume those cultures use a 12-hour clock? |
mkhamoyan commentedJun 19, 2024
My bad, |
PopSlime commentedJun 19, 2024
How about this? [Fact]publicvoidLongTimePattern_VerifyTimePatterns(){foreach(varcultureinCultureInfo.GetCultures(CultureTypes.AllCultures)){varpattern=culture.DateTimeFormat.LongTimePattern;varsegments=pattern.Split('\'');booluse12Hour=false;booluseAMPM=false;for(vari=0;i<segments.Length;i+=2){varsegment=segments[i];use12Hour|=segment.Contains('h',StringComparison.Ordinal);useAMPM|=segment.Contains('t',StringComparison.Ordinal);}Assert.True(!use12Hour||useAMPM,$"Bad time pattern for culture{culture.Name}: '{pattern}'");}} By the way, this fails on my PC (Windows) with |
mkhamoyan commentedJun 19, 2024
Looks good to me.
Yes , we should file an issue for that. |
src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Icu.csShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Icu.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Add tests verifying that all the short and long time patterns either usea 24-hour clock or have an AM/PM designator.
PopSlime commentedJun 19, 2024
@dotnet-policy-service agree |
tarekgh commentedJun 19, 2024
I don't think we can fix that as the patterns are picked from Windows. I suggest you mark your new test methods with the attribute and see if this can help? Line 264 in7934e64
|
PopSlime commentedJun 19, 2024
I'll do that, but I also want to see if similar issues are occurring on other platforms, so let's wait for these checks to be done. |
tarekgh commentedJun 19, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I am trying on my machine, and I am not getting the same results you are getting. running code like: varci=CultureInfo.GetCultureInfo("mi-NZ");Console.WriteLine($"{ci.Name} ..{ci.EnglishName} ..{ci.DateTimeFormat.ShortTimePattern} ..{ci.DateTimeFormat.LongTimePattern}");ci=CultureInfo.GetCultureInfo("mi");Console.WriteLine($"{ci.Name} ..{ci.EnglishName} ..{ci.DateTimeFormat.ShortTimePattern} ..{ci.DateTimeFormat.LongTimePattern}"); What Windows version do you have? I am wondering how you get this result? |
PopSlime commentedJun 19, 2024
It seems that the version of the CLDR data installed on my PC is below 36. The time format for
|
tarekgh commentedJun 19, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
ok, then the attribute Line 264 in7934e64
Line 10 in2a779ab
I meant using check like |
ilonatommy commentedJun 21, 2024
Current behavior was expected and other |
mkhamoyan commentedJun 21, 2024
/azp run runtime-ioslike,runtime-ioslikesimulator,runtime-maccatalyst |
| Azure Pipelines successfully started running 3 pipeline(s). |
mkhamoyan left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Looks good to me.
Let's wait for ios pipelines and then we can merge.
src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Icu.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
mkhamoyan commentedJun 21, 2024
/azp run runtime-ioslike,runtime-ioslikesimulator,runtime-maccatalyst |
| Azure Pipelines successfully started running 3 pipeline(s). |
PopSlime commentedJun 21, 2024
/azp run runtime |
| Commenter does not have sufficient privileges for PR 103681 in repo dotnet/runtime |
ilonatommy commentedJun 21, 2024
/azp run runtime |
| Azure Pipelines successfully started running 1 pipeline(s). |
* Fix the ICU time format conversion logicRevise the ICU time format conversion logic to support all unquoted literal texts and the `B` and `b` pattern symbols.Fixdotnet#103592* Clarify literal texts in the conversion logic* Add tests for verifying time patternsAdd tests verifying that all the short and long time patterns either usea 24-hour clock or have an AM/PM designator.* Fix literal single quote and literal backslash conversion* Refactor the literal quote conversion logic* Revise the test logic to ignore literal texts and check pattern redundancyModify the test logic so that it recognizes literal texts correctly, andfails if 12-hour and 24-hour clocks are used at the same time.* Revise the test logic to ensure all cultures are tested* Add comments to clarify the backslash conversion* Refactor the conversion logicSimplify some logic and improve readability.* Exclude bad ICU patterns from the tests* Exclude the VerifyTimePatterns tests from hybrid globalization on browser* Add missing usings* Improve readability of the for-loops
Revise the ICU time format conversion logic to support all unquoted literal texts and the
Bandbpattern symbols.Fix#103592