Skip to content

feat: switch timestamp representation to int64 usec #1332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix: properly handle number input
  • Loading branch information
alvarowolfx committed Feb 16, 2024
commit c543b26e323677427744929680695e61e1b3b246
3 changes: 3 additions & 0 deletions src/bigquery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2219,7 +2219,10 @@ export class BigQueryTimestamp {
} else {
pd = new PreciseDate(BigInt(value) * BigInt(1000));
}
} else if (value > 0) {
pd = new PreciseDate(BigInt(value) * BigInt(1000));
} else {
// Nan or negative values - invalid dates
pd = new PreciseDate(value);
}
// to keep backward compatibility, only converts with microsecond
Expand Down
11 changes: 11 additions & 0 deletions test/bigquery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,17 @@ describe('BigQuery', () => {
assert.strictEqual(timestamp.value, EXPECTED_VALUE);
});

it('should accept a number in microseconds', () => {
const ms = INPUT_PRECISE_DATE.valueOf(); // milliseconds
const us = (ms*1000) + INPUT_PRECISE_DATE.getMicroseconds(); // microseconds
let timestamp = bq.timestamp(us);
assert.strictEqual(timestamp.value, EXPECTED_VALUE_MICROS);

const usStr = `${us}`;
timestamp = bq.timestamp(usStr);
assert.strictEqual(timestamp.value, EXPECTED_VALUE_MICROS);
});

it('should accept a string with microseconds', () => {
const timestamp = bq.timestamp(INPUT_STRING_MICROS);
assert.strictEqual(timestamp.value, EXPECTED_VALUE_MICROS);
Expand Down