@google-cloud/bigquery
Advanced tools
Comparing version 7.5.0 to 7.5.1
@@ -452,2 +452,6 @@ /*! | ||
* | ||
* The recommended input here is a `Date` or `PreciseDate` class. | ||
* If passing as a `string`, it should be Timestamp literals: https://cloud.google.com/bigquery/docs/reference/standard-sql/lexical#timestamp_literals. | ||
* When passing a `number` input, it should be epoch seconds in float representation. | ||
* | ||
* @method BigQuery.timestamp | ||
@@ -462,2 +466,3 @@ * @param {Date|string} value The time. | ||
*/ | ||
static timestamp(value: Date | PreciseDate | string | number): BigQueryTimestamp; | ||
/** | ||
@@ -467,4 +472,8 @@ * A timestamp represents an absolute point in time, independent of any time | ||
* | ||
* @param {Date|string} value The time. | ||
* The recommended input here is a `Date` or `PreciseDate` class. | ||
* If passing as a `string`, it should be Timestamp literals: https://cloud.google.com/bigquery/docs/reference/standard-sql/lexical#timestamp_literals. | ||
* When passing a `number` input, it should be epoch seconds in float representation. | ||
* | ||
* @param {Date|string|string|number} value The time. | ||
* | ||
* @example | ||
@@ -477,3 +486,2 @@ * ``` | ||
*/ | ||
static timestamp(value: Date | PreciseDate | string | number): BigQueryTimestamp; | ||
timestamp(value: Date | PreciseDate | string | number): BigQueryTimestamp; | ||
@@ -1070,2 +1078,7 @@ /** | ||
* Timestamp class for BigQuery. | ||
* | ||
* The recommended input here is a `Date` or `PreciseDate` class. | ||
* If passing as a `string`, it should be Timestamp literals: https://cloud.google.com/bigquery/docs/reference/standard-sql/lexical#timestamp_literals. | ||
* When passing a `number` input, it should be epoch seconds in float representation. | ||
* | ||
*/ | ||
@@ -1075,2 +1088,3 @@ export declare class BigQueryTimestamp { | ||
constructor(value: Date | PreciseDate | string | number); | ||
fromFloatValue_(value: number): PreciseDate; | ||
} | ||
@@ -1077,0 +1091,0 @@ /** |
@@ -374,3 +374,4 @@ "use strict"; | ||
case 'TIMESTAMP': { | ||
value = BigQuery.timestamp(value); | ||
const pd = new precise_date_1.PreciseDate(BigInt(value) * BigInt(1000)); | ||
value = BigQuery.timestamp(pd); | ||
break; | ||
@@ -604,2 +605,6 @@ } | ||
* | ||
* The recommended input here is a `Date` or `PreciseDate` class. | ||
* If passing as a `string`, it should be Timestamp literals: https://cloud.google.com/bigquery/docs/reference/standard-sql/lexical#timestamp_literals. | ||
* When passing a `number` input, it should be epoch seconds in float representation. | ||
* | ||
* @method BigQuery.timestamp | ||
@@ -614,2 +619,5 @@ * @param {Date|string} value The time. | ||
*/ | ||
static timestamp(value) { | ||
return new BigQueryTimestamp(value); | ||
} | ||
/** | ||
@@ -619,4 +627,8 @@ * A timestamp represents an absolute point in time, independent of any time | ||
* | ||
* @param {Date|string} value The time. | ||
* The recommended input here is a `Date` or `PreciseDate` class. | ||
* If passing as a `string`, it should be Timestamp literals: https://cloud.google.com/bigquery/docs/reference/standard-sql/lexical#timestamp_literals. | ||
* When passing a `number` input, it should be epoch seconds in float representation. | ||
* | ||
* @param {Date|string|string|number} value The time. | ||
* | ||
* @example | ||
@@ -629,5 +641,2 @@ * ``` | ||
*/ | ||
static timestamp(value) { | ||
return new BigQueryTimestamp(value); | ||
} | ||
timestamp(value) { | ||
@@ -1329,2 +1338,7 @@ return BigQuery.timestamp(value); | ||
* Timestamp class for BigQuery. | ||
* | ||
* The recommended input here is a `Date` or `PreciseDate` class. | ||
* If passing as a `string`, it should be Timestamp literals: https://cloud.google.com/bigquery/docs/reference/standard-sql/lexical#timestamp_literals. | ||
* When passing a `number` input, it should be epoch seconds in float representation. | ||
* | ||
*/ | ||
@@ -1345,11 +1359,13 @@ class BigQueryTimestamp { | ||
else { | ||
pd = new precise_date_1.PreciseDate(BigInt(value) * BigInt(1000)); | ||
const floatValue = Number.parseFloat(value); | ||
if (!Number.isNaN(floatValue)) { | ||
pd = this.fromFloatValue_(floatValue); | ||
} | ||
else { | ||
pd = new precise_date_1.PreciseDate(value); | ||
} | ||
} | ||
} | ||
else if (value) { | ||
pd = new precise_date_1.PreciseDate(BigInt(value) * BigInt(1000)); | ||
} | ||
else { | ||
// Nan or 0 - invalid dates | ||
pd = new precise_date_1.PreciseDate(value); | ||
pd = this.fromFloatValue_(value); | ||
} | ||
@@ -1365,2 +1381,10 @@ // to keep backward compatibility, only converts with microsecond | ||
} | ||
fromFloatValue_(value) { | ||
const secs = Math.trunc(value); | ||
// Timestamps in BigQuery have microsecond precision, so we must | ||
// return a round number of microseconds. | ||
const micros = Math.trunc((value - secs) * 1e6 + 0.5); | ||
const pd = new precise_date_1.PreciseDate([secs, micros * 1000]); | ||
return pd; | ||
} | ||
} | ||
@@ -1367,0 +1391,0 @@ exports.BigQueryTimestamp = BigQueryTimestamp; |
@@ -7,2 +7,11 @@ # Changelog | ||
## [7.5.1](https://github.com/googleapis/nodejs-bigquery/compare/v7.5.0...v7.5.1) (2024-03-14) | ||
### Bug Fixes | ||
* Add better documentation around usage of BigQueryTimestamp class and .timestamp method. ([2b2c3e0](https://github.com/googleapis/nodejs-bigquery/commit/2b2c3e0b8e9c13d23aa54e7a85a861c61410bd4b)) | ||
* BigQueryTimestamp should keep accepting floats [#1339](https://github.com/googleapis/nodejs-bigquery/issues/1339) ([2b2c3e0](https://github.com/googleapis/nodejs-bigquery/commit/2b2c3e0b8e9c13d23aa54e7a85a861c61410bd4b)) | ||
* Restores BigQueryTimestamp behavior to accept a numeric value in the constructor representing epoch-seconds. The affected 7.5.0 version would parse a numeric value as epoch-microseconds. ([2b2c3e0](https://github.com/googleapis/nodejs-bigquery/commit/2b2c3e0b8e9c13d23aa54e7a85a861c61410bd4b)) | ||
## [7.5.0](https://github.com/googleapis/nodejs-bigquery/compare/v7.4.0...v7.5.0) (2024-02-21) | ||
@@ -9,0 +18,0 @@ |
{ | ||
"name": "@google-cloud/bigquery", | ||
"description": "Google BigQuery Client Library for Node.js", | ||
"version": "7.5.0", | ||
"version": "7.5.1", | ||
"license": "Apache-2.0", | ||
@@ -6,0 +6,0 @@ "author": "Google LLC", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
704407
14461