Skip to content
Source
Sign inSign up
TanStack/db

fix(db): support Temporal values in query comparison operators #1519

Mergedobeattie(GitHub profile, opens in a new tab)merged 9 commits intomain fromrefs/pull/1519/headmerged by kevin-dp(GitHub profile, opens in a new tab)

Showing 5 changed files with 81 additions and 12 deletions (loading 2).

x
0 of 5 viewed, 5 left
12 additions and 0 deletions.changeset/temporal-comparators.mdAdded
View file
@@ -0,0 +1,12 @@
+---
+'@tanstack/db': patch
+---
+​
+Support Temporal values in the `gt`/`gte`/`lt`/`lte` query operators. Comparisons now dispatch to the Temporal types' static `compare()` instead of the native relational operators, which throw on Temporal objects (`valueOf()` is designed to throw). `orderBy` uses the same logic, so filtering and ordering now agree — previously `orderBy` compared Temporal values lexicographically by their `toString()`, which mis-ordered equivalent `Duration` forms (`PT60M` vs `PT1H`) and same-instant `ZonedDateTime` values in different zones.
+​
+Note two intentional behavior changes for `orderBy` over Temporal columns:
+​
+- Ordering `Temporal.PlainMonthDay` values now throws a `TypeError`, since the type has no defined ordering (previously they were silently ordered by string).
+- Ordering mixed Temporal types (e.g. `PlainDate` vs `PlainDateTime`) now throws a `TypeError` instead of comparing their string forms.
+​
+Equality (`eq`) is unchanged: `ZonedDateTime` equality still treats the zone as part of identity, and equivalent `Duration` forms remain unequal, mirroring Temporal's `.equals()` vs `.compare()` semantics.
5 additions and 6 deletionspackages/db/src/query/compiler/evaluators.tsModified
View file
@@ -5,6 +5,7 @@
} from '../../errors.js'
import {
areValuesEqual,
+ compareValues,
isUnorderable,
normalizeValue,
} from '../../utils/comparison.js'
@@ -265,12 +266,10 @@