Skip to content

Commit ab5bcc9

Browse files
committed
Tests for eq comparison of Date objects
1 parent ad306a1 commit ab5bcc9

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

packages/db/tests/query/compiler/evaluators.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,36 @@ describe(`evaluators`, () => {
506506
}
507507
})
508508

509+
it(`handles eq with Date objects (should compare by getTime(), not reference)`, () => {
510+
// Create two Date objects with the same time value
511+
// They are different object instances but represent the same moment
512+
const date1 = new Date(`2024-01-15T10:30:45.123Z`)
513+
const date2 = new Date(`2024-01-15T10:30:45.123Z`)
514+
515+
// Verify they are different object references
516+
expect(date1).not.toBe(date2)
517+
// But they have the same time value
518+
expect(date1.getTime()).toBe(date2.getTime())
519+
520+
const func = new Func(`eq`, [new Value(date1), new Value(date2)])
521+
const compiled = compileExpression(func)
522+
523+
// Should return true because they represent the same time
524+
// Currently this fails because eq() does referential comparison
525+
expect(compiled({})).toBe(true)
526+
})
527+
528+
it(`handles eq with Date objects with different times`, () => {
529+
const date1 = new Date(`2024-01-15T10:30:45.123Z`)
530+
const date2 = new Date(`2024-01-15T10:30:45.124Z`) // 1ms later
531+
532+
const func = new Func(`eq`, [new Value(date1), new Value(date2)])
533+
const compiled = compileExpression(func)
534+
535+
// Should return false because they represent different times
536+
expect(compiled({})).toBe(false)
537+
})
538+
509539
it(`handles eq with Uint8Arrays created with length (repro case)`, () => {
510540
// Reproduction of user's issue: new Uint8Array(5) creates [0,0,0,0,0]
511541
const array1 = new Uint8Array(5) // Creates array of length 5, all zeros

0 commit comments

Comments
 (0)