Parse and serialize timestamp infinity as Infinity - fixes #728 - #1184
Open
spokodev wants to merge 1 commit into
Open
Parse and serialize timestamp infinity as Infinity - fixes #728#1184spokodev wants to merge 1 commit into
spokodev wants to merge 1 commit into
Conversation
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.
timestamptz/timestamp/datecolumns can hold the special valuesinfinityand-infinity— e.g.expires timestamptz DEFAULT 'infinity'for "never expires". Postgres.js currently parses these throughnew Date('infinity'), which yields anInvalid Date:.getTime()isNaN, so every subsequent date comparison silently breaks. Reported in #728 (with a second report confirming it).node-postgres maps these to JS
Infinity/-Infinity(viapostgres-date). This brings postgres.js in line.Change (
src/types.js,datetype)'infinity' → Infinity,'-infinity' → -Infinity, otherwisenew Date(x)as before.Infinity → 'infinity',-Infinity → '-infinity', otherwise unchanged. Without this half, writing a parsedInfinityback through the date serializer hitsnew Date(Infinity).toISOString(), which throwsRangeError: Invalid time value— the two halves together let the value round-trip.Behavior change (intentional)
Reading an
infinitytimestamp now returns the numberInfinityinstead of anInvalid Date. Code doingrow.col.getTime()was already gettingNaN; it now gets a value that compares correctly (Infinity > anyDate). This matches node-postgres and the underlying Postgres semantics.Tests
Added alongside the existing
Datecases — parse of'infinity'/'-infinity', plus round-trip viasql.typed(±Infinity, 1184). Verified failing onmain(parse →Invalid Date, round-trip →RangeError) and passing after the change; the normalDatepath is unaffected.Refs: Postgres date/time special values, node-postgres /
postgres-date.