-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Fix "MMM.yy" date parsing in German culture. #114169
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
Conversation
Tagging subscribers to this area: @dotnet/area-system-globalization |
@dotnet-policy-service agree |
@pra2892 thanks for submitting the PR. I am seeing you added submodule called runtime to this PR. Please delete it. |
// Search genitive form. | ||
if ((dtfi.FormatFlags & DateTimeFormatFlags.UseGenitiveMonth) != 0) | ||
// Only search genitive form if useGenitiveForm is true | ||
if ((dtfi.FormatFlags & DateTimeFormatFlags.UseGenitiveMonth) != 0 && useGenitiveForm) |
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.
I am not sure I understand this fix. the value of useGenitiveForm
is always false so the condition will always be evaluated as false.
The fix should be, passing the format string to this method MatchAbbreviatedMonthName
. and when checking
dtfi.FormatFlags & DateTimeFormatFlags.UseGenitiveMonth) != 0
, can check if format string has d
or dd
specifiers.
* Fix "MMM.yy" date parsing in German culture. #114169 * Fix "MMM.yy" date parsing in German culture. #114169 * Fix "MMM.yy" date parsing in German culture. #114169 v3 * Fix "MMM.yy" date parsing in German culture. #114169 [Testing] * Fix "MMM.yy" date parsing in German culture. #114169 [Testing] v1 * Fix the test --------- Co-authored-by: Tarek Mahmoud Sayed <[email protected]>
Fix DateTime.TryParseExact for "MMM.yy" format in German culture
This commit fixes an issue where DateTime.TryParseExact fails to parse dates formatted with "MMM.yy" in German culture (de-DE). The problem occurs because the parsing logic incorrectly tries to match against genitive month names when parsing abbreviated month names without day specifiers.
According to the documentation, genitive month names should only be used when the format pattern contains day specifiers ('d' or 'dd'). The "MMM.yy" format doesn't contain day specifiers, so regular month names should be used.
Modified the MatchAbbreviatedMonthName method to conditionally use genitive month names only when appropriate, fixing scenarios like:
Fixes #114159