Skip to content

Cannot instantiate PreciseDate with JS primitive number 0 or BigInt(0) #250

Open
@alvarowolfx

Description

@alvarowolfx

When trying to instantiate the PreciseDate class with the zero epoch time, it fails.

Environment details

  • OS: macOS
  • Node.js version: 18.12.1
  • npm version: 9.4.0
  • @google-cloud/precise-date version: 4.0.0

Steps to reproduce

  1. Try to instantiate a PreciseDate with BigInt(0) or 0
  2. Throws Error: TypeError: Cannot convert a BigInt value to a number at PreciseDate

The issue is that this line

if (time && typeof time !== 'number' && !(time instanceof Date)) {
, needs to explicitly check for zero values, as zero is a valid PreciseDate.

I'll try to submit a PR later, but in the meantime a hotfix will be applyed on the BigQuery library for this issue by calling PreciseDate.parseFull + preciseDateInstance.setFulltime

Reference issue: googleapis/nodejs-bigquery#1353

Metadata

Metadata

Assignees

Labels

priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions