Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions js/src/visitor/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,21 @@ function wrapSet<T extends DataType>(fn: (data: Data<T>, _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 */
Expand Down
11 changes: 10 additions & 1 deletion js/test/unit/vector/date-vector-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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();
Expand All @@ -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 = () => [
Expand Down