Uh oh!
There was an error while loading. Please reload this page.
Fix the ICU time format conversion logic - #103681
Conversation
Revise the ICU time format conversion logic to support all unquoted literal texts and the `B` and `b` pattern symbols. Fixdotnet#103592
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
commented
Jun 19, 2024
@PopSlime thanks for submitting the PR. |
mkhamoyan
commented
Jun 19, 2024
/azp run runtime-extra-platforms |
|
Azure Pipelines successfully started running 1 pipeline(s). |
@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. |
@PopSlime I was thinking something like below (same test case for shorttime patterns under here) would validate the change. This should be consistent for all platforms and devices. |
PopSlime
commented
Jun 19, 2024
@mkhamoyan Is it safe to assume those cultures use a 12-hour clock? |
mkhamoyan
commented
Jun 19, 2024
My bad, |
PopSlime
commented
Jun 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
commented
Jun 19, 2024
Looks good to me.
Yes , we should file an issue for that. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Add tests verifying that all the short and long time patterns either use a 24-hour clock or have an AM/PM designator.
PopSlime
commented
Jun 19, 2024
@dotnet-policy-service agree |
tarekgh
commented
Jun 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? |
PopSlime
commented
Jun 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. |
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
commented
Jun 19, 2024
It seems that the version of the CLDR data installed on my PC is below 36. The time format for
|
ok, then the attribute
is not going to help. You may try using something like
to avoid the failure. I meant using check like |
ilonatommy
commented
Jun 21, 2024
Current behavior was expected and other |
mkhamoyan
commented
Jun 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.
Looks good to me.
Let's wait for ios pipelines and then we can merge.
Uh oh!
There was an error while loading. Please reload this page.
mkhamoyan
commented
Jun 21, 2024
/azp run runtime-ioslike,runtime-ioslikesimulator,runtime-maccatalyst |
|
Azure Pipelines successfully started running 3 pipeline(s). |
PopSlime
commented
Jun 21, 2024
/azp run runtime |
|
Commenter does not have sufficient privileges for PR 103681 in repo dotnet/runtime |
ilonatommy
commented
Jun 21, 2024
/azp run runtime |
|
Azure Pipelines successfully started running 1 pipeline(s). |
* Fix the ICU time format conversion logic Revise 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 patterns Add tests verifying that all the short and long time patterns either use a 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 redundancy Modify the test logic so that it recognizes literal texts correctly, and fails 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 logic Simplify 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