Fix DateTime parsing when AM designator prefix PM designator#123024
Merged
tarekgh merged 3 commits intodotnet:mainfrom Jan 9, 2026
Merged
Fix DateTime parsing when AM designator prefix PM designator#123024tarekgh merged 3 commits intodotnet:mainfrom
tarekgh merged 3 commits intodotnet:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug in DateTime parsing where the AM designator is a prefix of the PM designator (e.g., "aM" and "aMP"). The fix ensures that when both designators match, the longer PM designator is used instead of incorrectly matching the shorter AM designator.
Key changes:
- Adds logic to check if PM designator starts with AM designator and prefers the longer match
- Includes a comprehensive test case that verifies both formatting and parsing with prefix scenario
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeParse.cs | Adds logic in MatchTimeMark to handle the case where AM designator is a prefix of PM designator by checking for and preferring the longer PM match |
| src/libraries/System.Runtime/tests/System.Runtime.Tests/System/DateTimeTests.cs | Adds test case TestParsingWithAmPrefixPm that validates DateTime parsing when AM designator ("aM") is a prefix of PM designator ("aMP") |
src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeParse.cs
Outdated
Show resolved
Hide resolved
stephentoub
reviewed
Jan 9, 2026
src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeParse.cs
Outdated
Show resolved
Hide resolved
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-datetime |
…DateTimeParse.cs Co-authored-by: Copilot <[email protected]>
stephentoub
reviewed
Jan 9, 2026
src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeParse.cs
Outdated
Show resolved
Hide resolved
stephentoub
reviewed
Jan 9, 2026
src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeParse.cs
Outdated
Show resolved
Hide resolved
Member
Author
Member
|
Likely makes sense to merge this PR. My PR is waiting on networking related changes. You can rewrite history on the other branch if you'd like to remove your change to avoid merge conflicts. |
jeffhandley
approved these changes
Jan 9, 2026
Member
Author
|
/ba-g failures are unrelated. |
This was referenced Jan 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CLDR globalization data updates changed the
ak-GHAM and PM designators toANandANW, respectively. The new values make the AM designator a prefix of the PM designator, which causes issues during date/time parsing: a value may be parsed as the AM designator even when the input contains the PM designator. The fix is to always attempt to parse the longest matching value first, and fall back to the shorter one if needed.