Skip to content

fix(adapter-pg): prepend + to expanded years in timestamps to prevent invalid date - #30412

Open
AbhilashG12 wants to merge 1 commit into
prisma:7.9.xfrom
AbhilashG12:fix/pg-expanded-years
Open

AbhilashG12 wants to merge 1 commit into
prisma:7.9.xfrom
AbhilashG12:fix/pg-expanded-years

Conversation

@AbhilashG12

Copy link
Copy Markdown

Linked issue

Fixes #30151

Summary

In @prisma/adapter-pg, timestamps with expanded years (more than 4 digits) were being silently deserialized into Invalid Date objects (getTime() === NaN).

This occurs because ECMAScript's Date.parse strictly enforces the ISO 8601 standard, which requires expanded years (>9999) to carry an explicit sign (+ or -). Postgres outputs dates like 202609-02-05 05:00:00, and normalize_timestamp was not appending the mandatory +, causing V8 to reject it.

This PR updates both normalize_timestamp and normalize_timestamptz to 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 downstream RangeError: Invalid time value crashes.

Testing performed

  • Added unit tests to conversion.test.ts to verify 4-digit and >4-digit boundaries for both timezone-aware and timezone-naive timestamps.
  • pnpm --filter @prisma/adapter-pg test

Skill update

n/a — internal only

… Invalid Date

Signed-off-by: AbhilashG12 <abhilashggg15@gmail.com>
@coderabbitai

coderabbitai Bot commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 791a2e35-3464-4543-bdea-cbc04d880115

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Comment @coderabbitai help to get the list of available commands.

@AbhilashG12

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

CodeRabbit chat interactions are restricted to organization members for this repository. Ask an organization member to interact with CodeRabbit, or set chat.allow_non_org_members: true in your configuration.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant