Skip to content

Commit

Permalink
Merge pull request #1 from alietors/patch-1
Browse files Browse the repository at this point in the history
Handle unconventional millis/micros
  • Loading branch information
MatasJonys authored Nov 4, 2021
2 parents 3e5d76b + 239bf59 commit 0f4d404
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 0f4d404

Please sign in to comment.