Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged

Conversation

@PopSlime
Copy link
Contributor

Revise the ICU time format conversion logic to support all unquoted literal texts and theB andb pattern symbols.

Fix#103592

mkhamoyan reacted with heart emoji
Revise the ICU time format conversion logic to support all unquoted literal texts and the `B` and `b` pattern symbols.Fixdotnet#103592
@dotnet-policy-servicedotnet-policy-servicebot added the community-contributionIndicates that the PR has been added by a community member labelJun 19, 2024
@PopSlime
Copy link
ContributorAuthor

PopSlime commentedJun 19, 2024
edited
Loading

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:

ICU patternResult (Old)Result (New)
a नि h:mmtt h:mmtt नि h:mm
ཆུ་ཚོད་h:mm:ss ah:mm:ss ttཆུ་ཚོད་h:mm:ss tt
ཆུ་ཚོད་ h སྐར་མ་ mm a h mm ttཆུ་ཚོད་ h སྐར་མ་ mm tt
Bh:mm:ssh:mm:sstth:mm:ss

More information can be found in the fixing issue.

@mkhamoyan
Copy link
Contributor

@mkhamoyan
Copy link
Contributor

/azp run runtime-extra-platforms

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@PopSlime
Copy link
ContributorAuthor

PopSlime commentedJun 19, 2024
edited
Loading

@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
Copy link
Contributor

mkhamoyan commentedJun 19, 2024
edited
Loading

@PopSlime I was thinking something like below (same test case for shorttime patterns underhere) would validate the change.

[Theory][InlineData("zh-TW")][InlineData("en-US")][InlineData("fr-FR")]public void LongTimePattern_ValidateAMPMDesignators(string cultureName){    var cultureInfo = new CultureInfo(cultureName);    var date = DateTime.Today + TimeSpan.FromDays(10) + TimeSpan.FromMinutes(10);    string formattedDateTime = date.ToString("T", cultureInfo);        Assert.True(formattedDateTime.Contains(cultureInfo.DateTimeFormat.AMDesignator));}

This should be consistent for all platforms and devices.
Now we see issue only in some android devices because of differentCLDR versions.

@PopSlime
Copy link
ContributorAuthor

@mkhamoyan Is it safe to assume those cultures use a 12-hour clock?fr-FR uses a 24-hour clock on my side.

@mkhamoyan
Copy link
Contributor

@mkhamoyan Is it safe to assume those cultures use a 12-hour clock?fr-FR uses a 24-hour clock on my side.

My bad,fr-FR shouldn't be there.

@PopSlime
Copy link
ContributorAuthor

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) withmi: 'h:mm:ss' andmi-NZ: 'h:mm:ss'. Should we address this in another issue?

@mkhamoyan
Copy link
Contributor

How about this?

Looks good to me.

By the way, this fails on my PC (Windows) withmi: 'h:mm:ss' andmi-NZ: 'h:mm:ss'. Should we address this in another issue?

Yes , we should file an issue for that.
Let's push in the PR and check how it behaves on other platforms.

@tarekghtarekgh self-requested a reviewJune 19, 2024 16:06
Add tests verifying that all the short and long time patterns either usea 24-hour clock or have an AM/PM designator.
@PopSlime
Copy link
ContributorAuthor

@dotnet-policy-service agree

@PopSlimePopSlime marked this pull request as ready for reviewJune 19, 2024 17:31
@tarekgh
Copy link
Member

By the way, this fails on my PC (Windows) with mi: 'h:mm:ss' and mi-NZ: 'h:mm:ss'. Should we address this in another issue?
Yes , we should file an issue for that.

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?

[ConditionalFact(typeof(PlatformDetection),nameof(PlatformDetection.IsIcuGlobalization))]

@PopSlime
Copy link
ContributorAuthor

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
Copy link
Member

tarekgh commentedJun 19, 2024
edited
Loading

this fails on my PC (Windows) with mi: 'h:mm:ss' and mi-NZ: 'h:mm:ss'.

I am trying on my machine, and I am not getting the same results you are getting.

mi-NZ .. Maori (New Zealand) .. h:mm tt .. h:mm:ss ttmi .. Maori .. h:mm tt .. h:mm:ss tt

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
Copy link
ContributorAuthor

It seems that the version of the CLDR data installed on my PC is below 36. The time format formi was fixed inunicode-org/cldr#104.

  • Operating system: Windows 10
  • Version number: 22H2
  • Internal version: 19045.4529

@tarekgh
Copy link
Member

tarekgh commentedJun 19, 2024
edited
Loading

ok, then the attribute

[ConditionalFact(typeof(PlatformDetection),nameof(PlatformDetection.IsIcuGlobalization))]
is not going to help. You may try using something like
if(PlatformDetection.WindowsVersion>=10||PlatformDetection.ICUVersion.Major>=55||PlatformDetection.IsHybridGlobalizationOnApplePlatform)
to avoid the failure.

I meant using check likeif (PlatformDetection.ICUVersion.Major >= 68) .

@ilonatommy
Copy link
Member

@PopSlime the tests are still failing. For now, can you exclude running this test with hype globalization? or special casefr-CA when encountering it?@ilonatommy@mkhamoyan do you have any better suggestion?@PopSlime already logged issue to tracking fixing fr-CA formats.

Current behavior was expected and otherHybridGlobalization tests are prepared for that. I am looking if we can provide a generic fix. For now this test can be blocked withPlatformDetection.IsNotHybridGlobalizationOnBrowser. The fix can get in in a separate PR

@mkhamoyan
Copy link
Contributor

/azp run runtime-ioslike,runtime-ioslikesimulator,runtime-maccatalyst

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

Copy link
Contributor

@mkhamoyanmkhamoyan left a 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.

@mkhamoyan
Copy link
Contributor

/azp run runtime-ioslike,runtime-ioslikesimulator,runtime-maccatalyst

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@PopSlime
Copy link
ContributorAuthor

/azp run runtime

ilonatommy reacted with thumbs up emoji

@azure-pipelines
Copy link

Commenter does not have sufficient privileges for PR 103681 in repo dotnet/runtime

@ilonatommy
Copy link
Member

/azp run runtime

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@tarekghtarekgh merged commit4b9a1b2 intodotnet:mainJun 21, 2024
rzikm pushed a commit to rzikm/dotnet-runtime that referenced this pull requestJun 24, 2024
* 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
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsJul 23, 2024
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.

Reviewers

@ilonatommyilonatommyilonatommy approved these changes

@tarekghtarekghAwaiting requested review from tarekgh

+1 more reviewer

@mkhamoyanmkhamoyanmkhamoyan approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

area-System.Globalizationcommunity-contributionIndicates that the PR has been added by a community member

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Incorrect general long time pattern for some cultures on Android

4 participants

@PopSlime@mkhamoyan@tarekgh@ilonatommy

[8]ページ先頭

©2009-2025 Movatter.jp