fix: support negative year (BC date) deserialization#4036
Open
daguimu wants to merge 1 commit intoalibaba:mainfrom
Open
fix: support negative year (BC date) deserialization#4036daguimu wants to merge 1 commit intoalibaba:mainfrom
daguimu wants to merge 1 commit intoalibaba:mainfrom
Conversation
…Time LocalDateTime with negative years (e.g. year -1 = 2 BC) serializes as "-0001-12-31 16:00:00" (20 chars). The readLocalDateTime method dispatched this to parseLocalDateTime20 which expects a different date format, causing it to fail with "read LocalDateTime error". Add handling for the -yyyy-MM-dd HH:mm:ss format in the string fallback path, supporting both space and T separators, and / delimiters. Fixes alibaba#3845
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
LocalDateTimewith negative years (BC dates) serializes correctly (e.g."-0001-12-31 16:00:00") but fails to deserialize with:Reproduction:
Root Cause
The negative year date string
"-0001-12-31 16:00:00"has length 20 (due to the leading-). ThereadLocalDateTime()method dispatches length-20 strings toparseLocalDateTime20(), which expects a completely different format (dd Mon yyyy HH:mm:ss). This returns null, and the string eventually falls through to an error.Fix
Added handling for the
-yyyy-MM-dd HH:mm:ssformat in the string fallback path ofreadLocalDateTime(). The fix:--yyyy-MM-dd HH:mm:ss(supporting bothandTseparators, and/delimiters)Tests Added
testNegativeYearRoundTrip— Serialize then deserialize a BC date, verify equalitytestNegativeYearDirectParse— Parse"-0001-12-31 16:00:00"and verify all componentstestNegativeYearWithT— Parse withTseparator:"-0001-12-31T16:00:00"testNegativeYearWithSlash— Parse with/delimiter:"-0001/12/31 16:00:00"testNegativeYearLarger— Year -100 (101 BC) round-triptestPositiveYearStillWorks— Regression test for normal datesImpact
Minimal — only affects deserialization of negative year datetime strings (20 chars starting with
-). Normal date parsing is unaffected.Fixes #3845