Skip to content

Commit

Permalink
Handle unconventional millis/micros
Browse files Browse the repository at this point in the history
We found that parquet files created from pyarrow have "unconventional" format for millis and micros. This change is not original it's a merge of 2 already proposed  PRs
ZJONSSON#65
ZJONSSON#45

We are struggling with those issues, it this something you will consider to merge? we can create our own fork but we believe is better having one library.
  • Loading branch information
alietors committed Jun 22, 2021
1 parent 3e5d76b commit 239bf59
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ function toPrimitive_TIMESTAMP_MILLIS(value) {
}

function fromPrimitive_TIMESTAMP_MILLIS(value) {
return new Date(+value);
return new Date(parseInt(value));
}

function toPrimitive_TIMESTAMP_MICROS(value) {
Expand All @@ -382,7 +382,13 @@ function toPrimitive_TIMESTAMP_MICROS(value) {
}

function fromPrimitive_TIMESTAMP_MICROS(value) {
return new Date(parseInt(value / 1000n));
if (value === undefined) {
return new Date(Nan);
} else if (typeof value === 'bigint') {
return new Date(parseInt(value / 1000n));
} else {
return new Date(value / 1000);
}
}

function toPrimitive_INTERVAL(value) {
Expand Down

0 comments on commit 239bf59

Please sign in to comment.