I had a use case to use chrono in my Bigquery models via UDFs. I have made the setup to import the chrono library and use it from my sql scripts. I am facing an issue with parseDate function when I pass a referenceDate along with date text.
for eg.
let testDate = new Date("2025-06-07")
let testText = "1 day ago"
const parsedDate = chrono.parseDate(periodText, refDate);
If I run the above code, parsedDate is always returning the previous day's date from current date instead of "2025-06-06" in Bigquery, If I run the same in a chrome console it works as expected. In a different realm it is causing issue.
export class ReferenceWithTimezone {
readonly instant: Date;
readonly timezoneOffset?: number | null;
constructor(input?: ParsingReference | Date) {
input = input ?? new Date();
if ( input instanceof Date ) {. // COMMENT : This always returns false.
this.instant = input;
this.timezoneOffset = null;
} else {
this.instant = input.instant ?? new Date();
this.timezoneOffset = toTimezoneOffset(input.timezone, this.instant);
}
}
// skip
}
input instanceof Date this statement always return false in bigquery.
I was able to get my use case working after modifying my function as follows, but wondering whether the multiple realm fix is feasible (Object.prototype.toString.call) ?
let testDate = new Date("2025-06-07")
let testText = "1 day ago"
let input = { "instant": testDate, "timezone": testDate.getTimezoneOffset() }
const parsedDate = chrono.parseDate(periodText, refDate);
I had a use case to use chrono in my Bigquery models via UDFs. I have made the setup to import the chrono library and use it from my sql scripts. I am facing an issue with parseDate function when I pass a referenceDate along with date text.
for eg.
If I run the above code, parsedDate is always returning the previous day's date from current date instead of "2025-06-06" in Bigquery, If I run the same in a chrome console it works as expected. In a different realm it is causing issue.
input instanceof Datethis statement always return false in bigquery.I was able to get my use case working after modifying my function as follows, but wondering whether the multiple realm fix is feasible (
Object.prototype.toString.call) ?