Skip to content

Commit

Permalink
review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
eugene-taran committed Oct 20, 2023
1 parent 5935808 commit 15f16b4
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/pubsub/src/logical-types/DateType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ export class DateType extends types.LogicalType {
return undefined
}
let dateInMillis = date.getTime() * 1000
// If number is not a safe integer, it will lose precision during conversion:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER
// Avsc will throw errors trying to convert number larger than Number.MAX_SAFE_INTEGER - 1
// Only possibility to fix is to use custom long types like BigInt, but still it will not work for json conversion,
// because of that limiting date to max possible date in micros, if received value larger than that
// https://github.com/mtth/avsc/wiki/Advanced-usage#custom-long-types
if (Number.isSafeInteger(dateInMillis)) {
return dateInMillis
} else {
Expand Down

0 comments on commit 15f16b4

Please sign in to comment.