From e49cdf93b46f30fd621cad2328091a9c1a15250c Mon Sep 17 00:00:00 2001 From: mShan0 <96149598+mShan0@users.noreply.github.com> Date: Wed, 7 Feb 2024 13:23:40 -0800 Subject: [PATCH] change datetime2 range check --- src/data-types/datetime2.ts | 10 +++++----- test/unit/data-type.js | 4 +++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/data-types/datetime2.ts b/src/data-types/datetime2.ts index 5299c3b9d..93ce132c7 100644 --- a/src/data-types/datetime2.ts +++ b/src/data-types/datetime2.ts @@ -5,9 +5,6 @@ import WritableTrackingBuffer from '../tracking-buffer/writable-tracking-buffer' const EPOCH_DATE = LocalDate.ofYearDay(1, 1); const NULL_LENGTH = Buffer.from([0x00]); -const MIN_DATE = new Date('January 1, 0001'); -const MAX_DATE = new Date('December 31, 9999'); - const DateTime2: DataType & { resolveScale: NonNullable } = { id: 0x2A, type: 'DATETIME2N', @@ -118,11 +115,14 @@ const DateTime2: DataType & { resolveScale: NonNullable MAX_DATE) { + if (year < 1 || year > 9999) { throw new TypeError('Out of range.'); } diff --git a/test/unit/data-type.js b/test/unit/data-type.js index 83cc9d3a4..3268a2253 100644 --- a/test/unit/data-type.js +++ b/test/unit/data-type.js @@ -322,7 +322,9 @@ describe('DateTime2', function() { describe('.validate', function() { it('returns a TypeError for dates that are out of range', function() { assert.throws(() => { - TYPES.DateTime2.validate(new Date('Dec 31, 2000')); + const testDate = new Date(); + testDate.setFullYear(0); + TYPES.DateTime2.validate(testDate); }, TypeError, 'Out of range.'); assert.throws(() => {