fix: timezone inconsistency in date type parsing #1084
Closed
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
The
date
type handler has inconsistent timezone handling between serialization and parsing, causing incorrect date values when the system timezone differs from UTC.Root Cause:
toISOString()
always outputs UTC formatnew Date(x)
interprets strings without timezone info as local timeThis asymmetry creates a double timezone conversion bug affecting PostgreSQL operations like
AT TIME ZONE
,DATE_TRUNC()
, and any timestamp operations in non-UTC system timezones.Example Bug:
Solution
Modified the
parse
function in thedate
type handler to treat strings without timezone information as UTC, matching the serialization behavior:This ensures:
timestamp
columns are parsed as UTC to match serializationtimestamptz
columns with timezone info remain unchangedTesting
Added comprehensive test cases covering:
AT TIME ZONE
operation correctnessRelated Issues
Fixes:
Impact: Resolves timezone inconsistencies for applications running in non-UTC timezones and ensures consistent behavior across different system locales.