From 15f16b43d9f0bdf6f89cf7790ba11d0bc2eac7ef Mon Sep 17 00:00:00 2001 From: Eugene Taran Date: Fri, 20 Oct 2023 15:33:17 +0200 Subject: [PATCH] review fixes --- packages/pubsub/src/logical-types/DateType.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/pubsub/src/logical-types/DateType.ts b/packages/pubsub/src/logical-types/DateType.ts index cb6459a..f68f71a 100644 --- a/packages/pubsub/src/logical-types/DateType.ts +++ b/packages/pubsub/src/logical-types/DateType.ts @@ -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 {