-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Closed
Description
Doing a round-trip with a JavaScript Date in apache-arrow/js sometimes results in wrong values:
import * as Arrow from "apache-arrow";
const date = new Date(1950, 1, 0);
const data = [{date}]
console.log("true date", date, +date);
const arrow = Arrow.tableFromJSON(data);
const [lo, hi] = arrow.batches[0].data.children[0].values;
console.log("encoded bytes", hi * (2**32) + lo);
for (const d of arrow) console.log("decoded date", d.date, +d.date)this prints:
❯ node test-arrow.js
true date 1950-01-30T23:00:00.000Z -628563600000
encoded bytes -628563600000
decoded date 1950-03-21T16:02:47.296Z -624268632704
As you can see there is a difference of 45 days. If I go and modify factories.ts and change dtypes.DateMillisecond to dtypes.Float64 (line 122), the decoding returns the correct number.
version information:
apache-arrow@^15.0.2:
resolved "https://registry.yarnpkg.com/apache-arrow/-/apache-arrow-15.0.2.tgz#d87c6447d64d6fab34aa70119362680b6617ce63"
❯ node -v
v20.11.1
macos sonoma 14.3.1 (23D60)
The results are correct for dates after epoch, but testing with new Date(1969, 11, 31); exhibits the problem.
Component(s)
JavaScript