diff --git a/js/src/visitor/set.ts b/js/src/visitor/set.ts index bef63416bc622..f8da1b7e76db3 100644 --- a/js/src/visitor/set.ts +++ b/js/src/visitor/set.ts @@ -108,21 +108,21 @@ function wrapSet(fn: (data: Data, _1: any, _2: any) => vo } /** @ignore */ -export const setEpochMsToDays = (data: Int32Array, index: number, epochMs: number) => { data[index] = Math.trunc(epochMs / 86400000); }; +export const setEpochMsToDays = (data: Int32Array, index: number, epochMs: number) => { data[index] = Math.floor(epochMs / 86400000); }; /** @ignore */ export const setEpochMsToMillisecondsLong = (data: Int32Array, index: number, epochMs: number) => { - data[index] = Math.trunc(epochMs % 4294967296); - data[index + 1] = Math.trunc(epochMs / 4294967296); + data[index] = Math.floor(epochMs % 4294967296); + data[index + 1] = Math.floor(epochMs / 4294967296); }; /** @ignore */ export const setEpochMsToMicrosecondsLong = (data: Int32Array, index: number, epochMs: number) => { - data[index] = Math.trunc((epochMs * 1000) % 4294967296); - data[index + 1] = Math.trunc((epochMs * 1000) / 4294967296); + data[index] = Math.floor((epochMs * 1000) % 4294967296); + data[index + 1] = Math.floor((epochMs * 1000) / 4294967296); }; /** @ignore */ export const setEpochMsToNanosecondsLong = (data: Int32Array, index: number, epochMs: number) => { - data[index] = Math.trunc((epochMs * 1000000) % 4294967296); - data[index + 1] = Math.trunc((epochMs * 1000000) / 4294967296); + data[index] = Math.floor((epochMs * 1000000) % 4294967296); + data[index + 1] = Math.floor((epochMs * 1000000) / 4294967296); }; /** @ignore */ diff --git a/js/test/unit/vector/date-vector-tests.ts b/js/test/unit/vector/date-vector-tests.ts index d658ac1d2767d..f8b4c1c7976d2 100644 --- a/js/test/unit/vector/date-vector-tests.ts +++ b/js/test/unit/vector/date-vector-tests.ts @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License. -import { DateDay, DateMillisecond, RecordBatchReader, Table } from 'apache-arrow'; +import { DateDay, DateMillisecond, RecordBatchReader, Table, vectorFromArray } from 'apache-arrow'; describe(`DateVector`, () => { it('returns days since the epoch as correct JS Dates', () => { @@ -27,6 +27,7 @@ describe(`DateVector`, () => { expect(date).toEqual(millis === null ? null : new Date(millis!)); } }); + it('returns millisecond longs since the epoch as correct JS Dates', () => { const table = new Table(RecordBatchReader.from(test_data)); const expectedMillis = expectedMillis64(); @@ -36,6 +37,14 @@ describe(`DateVector`, () => { expect(date).toEqual(millis === null ? null : new Date(millis!)); } }); + + it('returns the same date that was in the vector', () => { + const dates = [new Date(1950, 1, 0)]; + const vec = vectorFromArray(dates); + for (const date of vec) { + expect(date).toEqual(dates.shift()); + } + }); }); const expectedMillis32 = () => [