Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify MatchAbbreviatedMonthName comment #92405

Merged
merged 3 commits into from
Sep 25, 2023
Merged

Clarify MatchAbbreviatedMonthName comment #92405

merged 3 commits into from
Sep 25, 2023

Conversation

JanKrivanek
Copy link
Member

Context

When admiring the code of MatchAbbreviatedMonthName (credit to @cincuranet for pointing such gem) I found 2 nits:

  • comment incorrectly mentions cs-CZ culture as having month abberavitions with same prefixes.
  • the number of months is tested via GetMonthName (probably copied from MatchMonthName?), while following code calls GetAbbreviatedMonthName. Materializing monthNames is unnecessary here.

Details

Getting all the cultures (from my system) that have conflicting prefixes of abberavited month names:

    foreach (var cultureInfo in CultureInfo.GetCultures(CultureTypes.AllCultures))
    {
        DateTimeFormatInfo dtfi = cultureInfo.DateTimeFormat;

        int monthsInYear = (dtfi.GetAbbreviatedMonthName(13).Length == 0 ? 12 : 13);

        List<string> monthsAbbreviations =
            Enumerable.Range(1, monthsInYear)
                .Select(dtfi.GetAbbreviatedMonthName)
                .ToList();

        List<string> conflictingTuples = 
            // month indexes combinations
        Enumerable.Range(0, monthsInYear)
            .SelectMany(m1 => Enumerable.Range(m1 + 1, monthsInYear - m1 - 1).Select(m2 => (m1, m2)))
            // that are conflicting
            .Where(tpl =>
                monthsAbbreviations[tpl.m1].StartsWith(monthsAbbreviations[tpl.m2], true, cultureInfo)
                ||
                monthsAbbreviations[tpl.m2].StartsWith(monthsAbbreviations[tpl.m1], true, cultureInfo)
            )
            .Select(tpl => monthsAbbreviations[tpl.m1] + " : " + monthsAbbreviations[tpl.m2])
            .ToList();

        if (conflictingTuples.Any())
        {
            Console.WriteLine($"{cultureInfo.DisplayName} ({cultureInfo.Name}) : " + string.Join(", ", conflictingTuples));
        }
        else
        {
            // Console.WriteLine(cultureInfo.DisplayName + ": OK");
        }
    }
Tibetan (bo) : ???? : ?????, ???? : ?????, ???? : ?????
Tibetan (China) (bo-CN) : ???? : ?????, ???? : ?????, ???? : ?????
Tibetan (India) (bo-IN) : ???? : ?????, ???? : ?????, ???? : ?????
Duala (dua) : di : di?, di : di?
Duala (Cameroon) (dua-CM) : di : di?, di : di?
Dzongkha (dz) : ???? : ?????, ???? : ?????, ???? : ?????
Dzongkha (Bhutan) (dz-BT) : ???? : ?????, ???? : ?????, ???? : ?????
Ewondo (ewo) : nga : ngad, nga : ngab
Ewondo (Cameroon) (ewo-CM) : nga : ngad, nga : ngab
Guarani (gn) : Jasypo : Jasypotei, Jasypo : Jasypokoi, Jasypo : Jasypoapy, Jasypo : Jasyporundy, Jasypa : Jasypatei, Jasypa : Jasypakoi
Guarani (Paraguay) (gn-PY) : Jasypo : Jasypotei, Jasypo : Jasypokoi, Jasypo : Jasypoapy, Jasypo : Jasyporundy, Jasypa : Jasypatei, Jasypa : Jasypakoi
Bafia (ksf) : ?1 : ?10, ?1 : ?11, ?1 : ?12
Bafia (Cameroon) (ksf-CM) : ?1 : ?10, ?1 : ?11, ?1 : ?12
Cornish (kw) : Meu : Me, Me : Met
Cornish (United Kingdom) (kw-GB) : Meu : Me, Me : Met
Luba-Katanga (lu) : Lus : Lush
Luba-Katanga (Congo [DRC]) (lu-CD) : Lus : Lush
Kwasio (nmg) : ng1 : ng10, ng1 : ng11
Kwasio (Cameroon) (nmg-CM) : ng1 : ng10, ng1 : ng11
Rombo (rof) : M1 : M10, M1 : M11, M1 : M12
Rombo (Tanzania) (rof-TZ) : M1 : M10, M1 : M11, M1 : M12
Vietnamese (vi) : Thg 1 : Thg 10, Thg 1 : Thg 11, Thg 1 : Thg 12
Vietnamese (Vietnam) (vi-VN) : Thg 1 : Thg 10, Thg 1 : Thg 11, Thg 1 : Thg 12
Yangben (yav) : o.1 : o.10, o.1 : o.11, o.1 : o.12
Yangben (Cameroon) (yav-CM) : o.1 : o.10, o.1 : o.11, o.1 : o.12

Conclusion: Conflicts exist, so the code is correct - it cannot short circuit exit matching after first match identified. However the culture mentioned in the comment is not one of the cases. It originaly confused me - I thought the code was copy-pasted from MatchMonthName - where cs-CZ realy hase conflicting prefixes of full month names ("červen", "červenec").

@ghost
Copy link

ghost commented Sep 21, 2023

Tagging subscribers to this area: @dotnet/area-system-globalization
See info in area-owners.md if you want to be subscribed.

Issue Details

Context

When admiring the code of MatchAbbreviatedMonthName (credit to @cincuranet for pointing such gem) I found 2 nits:

  • comment incorrectly mentions cs-CZ culture as having month abberavitions with same prefixes.
  • the number of months is tested via GetMonthName (probably copied from MatchMonthName?), while following code calls GetAbbreviatedMonthName. Materializing monthNames is unnecessary here.

Details

Getting all the cultures (from my system) that have conflicting prefixes of abberavited month names:

    foreach (var cultureInfo in CultureInfo.GetCultures(CultureTypes.AllCultures))
    {
        DateTimeFormatInfo dtfi = cultureInfo.DateTimeFormat;

        int monthsInYear = (dtfi.GetAbbreviatedMonthName(13).Length == 0 ? 12 : 13);

        List<string> monthsAbbreviations =
            Enumerable.Range(1, monthsInYear)
                .Select(dtfi.GetAbbreviatedMonthName)
                .ToList();

        List<string> conflictingTuples = 
            // month indexes combinations
        Enumerable.Range(0, monthsInYear)
            .SelectMany(m1 => Enumerable.Range(m1 + 1, monthsInYear - m1 - 1).Select(m2 => (m1, m2)))
            // that are conflicting
            .Where(tpl =>
                monthsAbbreviations[tpl.m1].StartsWith(monthsAbbreviations[tpl.m2], true, cultureInfo)
                ||
                monthsAbbreviations[tpl.m2].StartsWith(monthsAbbreviations[tpl.m1], true, cultureInfo)
            )
            .Select(tpl => monthsAbbreviations[tpl.m1] + " : " + monthsAbbreviations[tpl.m2])
            .ToList();

        if (conflictingTuples.Any())
        {
            Console.WriteLine($"{cultureInfo.DisplayName} ({cultureInfo.Name}) : " + string.Join(", ", conflictingTuples));
        }
        else
        {
            // Console.WriteLine(cultureInfo.DisplayName + ": OK");
        }
    }
Tibetan (bo) : ???? : ?????, ???? : ?????, ???? : ?????
Tibetan (China) (bo-CN) : ???? : ?????, ???? : ?????, ???? : ?????
Tibetan (India) (bo-IN) : ???? : ?????, ???? : ?????, ???? : ?????
Duala (dua) : di : di?, di : di?
Duala (Cameroon) (dua-CM) : di : di?, di : di?
Dzongkha (dz) : ???? : ?????, ???? : ?????, ???? : ?????
Dzongkha (Bhutan) (dz-BT) : ???? : ?????, ???? : ?????, ???? : ?????
Ewondo (ewo) : nga : ngad, nga : ngab
Ewondo (Cameroon) (ewo-CM) : nga : ngad, nga : ngab
Guarani (gn) : Jasypo : Jasypotei, Jasypo : Jasypokoi, Jasypo : Jasypoapy, Jasypo : Jasyporundy, Jasypa : Jasypatei, Jasypa : Jasypakoi
Guarani (Paraguay) (gn-PY) : Jasypo : Jasypotei, Jasypo : Jasypokoi, Jasypo : Jasypoapy, Jasypo : Jasyporundy, Jasypa : Jasypatei, Jasypa : Jasypakoi
Bafia (ksf) : ?1 : ?10, ?1 : ?11, ?1 : ?12
Bafia (Cameroon) (ksf-CM) : ?1 : ?10, ?1 : ?11, ?1 : ?12
Cornish (kw) : Meu : Me, Me : Met
Cornish (United Kingdom) (kw-GB) : Meu : Me, Me : Met
Luba-Katanga (lu) : Lus : Lush
Luba-Katanga (Congo [DRC]) (lu-CD) : Lus : Lush
Kwasio (nmg) : ng1 : ng10, ng1 : ng11
Kwasio (Cameroon) (nmg-CM) : ng1 : ng10, ng1 : ng11
Rombo (rof) : M1 : M10, M1 : M11, M1 : M12
Rombo (Tanzania) (rof-TZ) : M1 : M10, M1 : M11, M1 : M12
Vietnamese (vi) : Thg 1 : Thg 10, Thg 1 : Thg 11, Thg 1 : Thg 12
Vietnamese (Vietnam) (vi-VN) : Thg 1 : Thg 10, Thg 1 : Thg 11, Thg 1 : Thg 12
Yangben (yav) : o.1 : o.10, o.1 : o.11, o.1 : o.12
Yangben (Cameroon) (yav-CM) : o.1 : o.10, o.1 : o.11, o.1 : o.12

Conclusion: Conflicts exist, so the code is correct - it cannot short circuit exit matching after first match identified. However the culture mentioned in the comment is not one of the cases. It originaly confused me - I thought the code was copy-pasted from MatchMonthName - where cs-CZ realy hase conflicting prefixes of full month names ("červen", "červenec").

Author: JanKrivanek
Assignees: JanKrivanek
Labels:

area-System.Globalization

Milestone: -

@tarekgh
Copy link
Member

tarekgh commented Sep 21, 2023

@JanKrivanek thanks for helping with this. Could you please try to add some test for such a change? Maybe testing with vi-VN? Note, if you add a test, ensure it passes when using ICU (the default case) and NLS too. if there is a difference in behavior you can restrict the test to ICU only case.

@JanKrivanek
Copy link
Member Author

/azp run

@azure-pipelines
Copy link

You have several pipelines (over 10) configured to build pull requests in this repository. Specify which pipelines you would like to run by using /azp run [pipelines] command. You can specify multiple pipelines using a comma separated list.

@tarekgh tarekgh closed this Sep 22, 2023
@tarekgh tarekgh reopened this Sep 22, 2023
@tarekgh
Copy link
Member

tarekgh commented Sep 24, 2023

/azp run runtime-nativeaot-outerloop

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@tarekgh
Copy link
Member

tarekgh commented Sep 25, 2023

@JanKrivanek I am trying to follow up to see what is wrong with CI legs which are not finishing. I know this is unrelated to your change, but we need to resolve it before we merge.

@JanKrivanek
Copy link
Member Author

Appreciated @tarekgh!
Lm know if there would be anything I should do.
We can as well try to temporarily revert the code change, keeping just the comment change, to have 100% confidence it's not change related

@tarekgh
Copy link
Member

tarekgh commented Sep 25, 2023

@JanKrivanek it doesn't matter if the change is related or not. The CI leg shouldn't hang too long anyway. This is what we need to resolve.

@agocke could you please help look at these hanging CI legs?

@tarekgh tarekgh merged commit b598ce9 into main Sep 25, 2023
185 of 188 checks passed
@jkotas jkotas deleted the JanKrivanek-patch-1 branch October 13, 2023 01:49
@ghost ghost locked as resolved and limited conversation to collaborators Nov 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants