duckdb/duckdb-wasm

`test_all_types ` - Timestamp values are out of range of valid JS Date objects

kaciakmaciak opened this issue · 0 comments

What happens?

Not sure if this is a bug or it's intentional, so I apologise if this is not a bug.

When using test_all_types() together with castTimestampToDate: true the timestamps are cast into invalid dates. This is due to maximum timestamp in JavaScript being slightly smaller than Number.MAX_SAFE_INTEGER. See MDN.

To Reproduce

const db = new duckdb.AsyncDuckDB(logger, worker);
await db.instantiate(bundle.mainModule, bundle.pthreadWorker);
await db.open({
  query: {
    castTimestampToDate: true,
  }
});
const conn = await db.connect();
const result = await conn.query(`
  SELECT
    "timestamp",
    "timestamp_s",
    "timestamp_ms",
    "timestamp_ns",
    "timestamp_tz",
    "timestamp_array",
    "timestamptz_array",
    epoch_ms(-8640000000000000) AS min_date,
    epoch_ms(8640000000000000) AS max_date
  FROM test_all_types()
`);
// timestamp, timestamp_ms, timestamp_s, timestamp_tz are all invalid dates
// min_date and max_date are valid
console.log(result.toArray().map((item) => item.toJSON()));

Please see an example in Codesandbox.

Browser/Environment:

Any

Device:

Any

DuckDB-Wasm Version:

1.28.1-dev248.0

DuckDB-Wasm Deployment:

N/A

Full Name:

Katarina Anton

Affiliation:

Individual