fix(adapter-pg): prepend + to expanded years in timestamps to prevent invalid date - #30412
AbhilashG12 wants to merge 1 commit into
Conversation
… Invalid Date Signed-off-by: AbhilashG12 <abhilashggg15@gmail.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Comment |
|
@coderabbitai review |
|
CodeRabbit chat interactions are restricted to organization members for this repository. Ask an organization member to interact with CodeRabbit, or set |
Linked issue
Fixes #30151
Summary
In
@prisma/adapter-pg, timestamps with expanded years (more than 4 digits) were being silently deserialized intoInvalid Dateobjects (getTime() === NaN).This occurs because ECMAScript's
Date.parsestrictly enforces the ISO 8601 standard, which requires expanded years (>9999) to carry an explicit sign (+or-). Postgres outputs dates like202609-02-05 05:00:00, andnormalize_timestampwas not appending the mandatory+, causing V8 to reject it.This PR updates both
normalize_timestampandnormalize_timestamptzto perform a fast regex check (/^\d{5,}/.test()). If the normalized string starts with 5 or more digits, it prepends the mandatory+sign. This resolves downstreamRangeError: Invalid time valuecrashes.Testing performed
conversion.test.tsto verify 4-digit and >4-digit boundaries for both timezone-aware and timezone-naive timestamps.pnpm --filter @prisma/adapter-pg testSkill update
n/a — internal only