Fix Rfc3339DateJsonAdapter to use UTC for date-only strings#2124
Open
amitmishra11 wants to merge 1 commit into
Open
Fix Rfc3339DateJsonAdapter to use UTC for date-only strings#2124amitmishra11 wants to merge 1 commit into
amitmishra11 wants to merge 1 commit into
Conversation
When parsing a date string with no time or timezone component (e.g. "2025-11-20"), the adapter was using the host machine's time zone via the default GregorianCalendar constructor. The code even contained a comment acknowledging this as a bug. This change parses date-only strings in UTC, consistent with how dates that carry an explicit "Z" suffix are handled. The test for this case is updated to assert UTC behaviour, and the now-unused newDateWithHostZone helper is removed. Fixes square#2046 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Fixes #2046
Bug
Rfc3339DateJsonAdapteruses the host machine's default time zone whenparsing a date string that has no time or timezone component (e.g.
"2025-11-20"). The parsing code inIso8601Utils.ktcontained acomment that directly acknowledged this:
This means two machines in different time zones would produce different
Datevalues from the same JSON input, which is surprising andinconsistent with how dates that carry an explicit
Zsuffix arehandled.
Fix
Replace the default-timezone
GregorianCalendarconstructor call withan explicit UTC calendar, matching the pattern already used for the
full datetime path. The fix mirrors what the existing code does when a
timezone is present.
Before:
After:
Test changes
absentTimeZonetest now asserts that"1970-01-01"producesthe same
Dateas"1970-01-01Z"(midnight UTC)."2025-11-20".newDateWithHostZonehelper, which existed only to document theold (incorrect) behaviour, is removed.
Verification