-
Notifications
You must be signed in to change notification settings - Fork 276
Open
Description
Describe the bug
- Run a query that returns a date using duckdb in a node environment, say something like
await db.all("SELECT DATE '2022-01-01' as dt")
- stringify the result
Expected:
1640995200000
Actual:
"""2022-01-01T00:00:00.000Z"""
To Reproduce
import { Database } from 'duckdb-async';
Database.create(":memory:")
const t = await db.all("SELECT DATE '2022-01-01' as dt");
// expect: 1640995200000
console.warn(stringify(t));
// actual: """2022-01-01T00:00:00.000Z"""
// expect: 1640995200000
console.warn(stringify(t, { cast: { date: (x) => x.getTime().toString() } }));
// actual: """2022-01-01T00:00:00.000Z"""
// expect: 1640995200000
console.warn(stringify(t, { cast: { object: (x) => x.getTime().toString() } }));
// actual: 1640995200000
Additional context
Some discussion in this stack overflow answer: https://stackoverflow.com/questions/643782/how-to-check-whether-an-object-is-a-date
Looks like the issue is that instanceof Date
only works within the same frame/realm.
date-fns handles it this way.
Metadata
Metadata
Assignees
Labels
No labels