googleapis / nodejs-precise-date

A simple utility for precise-dateing functions and classes.
Apache License 2.0
12 stars 4 forks source link

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

Open alvarowolfx opened 5 months ago

alvarowolfx commented 5 months ago

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

Environment details

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 https://github.com/googleapis/nodejs-precise-date/blob/04b3784b0a9948687cbd98a2be376246589c372c/src/index.ts#L122 , 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: https://github.com/googleapis/nodejs-bigquery/issues/1353