Fix "MMM.yy" date parsing in German culture. #114169#114194
Fix "MMM.yy" date parsing in German culture. #114169#114194tarekgh merged 12 commits intodotnet:mainfrom
Conversation
|
Tagging subscribers to this area: @dotnet/area-system-globalization |
src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeParse.cs
Outdated
Show resolved
Hide resolved
|
It would probably be good with some tests for this kind of case. |
src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeParse.cs
Show resolved
Hide resolved
|
@pra2892 thanks again for submitting the PR. This looks good. We need to add some tests to ensure we'll not break the behavior in the future. I would suggest in the test you create a culture like the following and ensure setting var culture = new CultureInfo("de-DE");
culture.DateTimeFormat.AbbreviatedMonthGenitiveNames = ["Jan.", "Feb.", "März", "Apr.", "Mai", "Juni", "Juli", "Aug.", "Sept", "Okt.", "Nov.", "Dez.", ""];
culture.DateTimeFormat.MonthGenitiveNames = ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember.", ''"];
culture.DateTimeFormat.DayNames = ["Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"];
culture.DateTimeFormat.DateSeparator = ".";Then you add test cases:
You need to add the tests to the file https://github.com/dotnet/runtime/blob/main/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/DateTimeTests.cs |
|
Two small "corrections"/improvements (especially "Sept." because it is the only one with 5 chars): var culture = new CultureInfo("de-DE");
culture.DateTimeFormat.AbbreviatedMonthGenitiveNames = ["Jan.", "Feb.", "März", "Apr.", "Mai", "Juni", "Juli", "Aug.", "Sept.", "Okt.", "Nov.", "Dez.", ""];
culture.DateTimeFormat.MonthGenitiveNames = ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember", ''"];
culture.DateTimeFormat.DayNames = ["Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"];
culture.DateTimeFormat.DateSeparator = "."; |
|
@ANahr I intentionally used dot at the end of the |
src/libraries/System.Runtime/tests/System.Runtime.Tests/System/DateTimeTests.cs
Outdated
Show resolved
Hide resolved
|
@pra2892 did you have a chance to address my comment #114194 (review)? |
|
@pra2892 I have pushed the test fix to this PR so we can merge it. |
|
/ba-g the failure is already tracked with #114465 |
This solution handles all the edge cases:
FormatContainsDayOfMonthSpecifiermethod properly skips 'd' characters inside quotes.\and%escape characters are handled.This solution should work correctly in all scenarios, including the specific case mentioned with "MMM dd" format in German culture.