From 1a703e2f8a31fff6ef63569ff8074e49eb502a37 Mon Sep 17 00:00:00 2001 From: Rocky Madden Date: Wed, 26 Jun 2024 14:26:47 -0600 Subject: [PATCH] fix: correct SmallDateTime upper bound range (#1621) Co-authored-by: Michael Sun <47126816+MichaelSun90@users.noreply.github.com> --- src/data-types/smalldatetime.ts | 3 ++- test/unit/data-type.js | 6 +----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/data-types/smalldatetime.ts b/src/data-types/smalldatetime.ts index 6169fc246..4748426ed 100644 --- a/src/data-types/smalldatetime.ts +++ b/src/data-types/smalldatetime.ts @@ -79,7 +79,8 @@ const SmallDateTime: DataType = { if (year === 2079) { // Month is 0-indexed, i.e. Jan = 0, Dec = 11 - if (month > 4 || (month === 4 && date > 6)) { + // See: https://learn.microsoft.com/en-us/sql/t-sql/data-types/smalldatetime-transact-sql?view=sql-server-ver16 + if (month > 5 || (month === 5 && date > 6)) { throw new TypeError('Out of range.'); } } diff --git a/test/unit/data-type.js b/test/unit/data-type.js index 999648b07..be24625fa 100644 --- a/test/unit/data-type.js +++ b/test/unit/data-type.js @@ -1072,16 +1072,12 @@ describe('SmallDateTime', function() { TYPES.SmallDateTime.validate(new Date('Dec 31, 1889')); }, TypeError, 'Out of range.'); - assert.throws(() => { - TYPES.SmallDateTime.validate(new Date('May 7, 2079')); - }, TypeError, 'Out of range.'); - assert.throws(() => { TYPES.SmallDateTime.validate(new Date('Jan 1, 2080')); }, TypeError, 'Out of range.'); assert.throws(() => { - TYPES.SmallDateTime.validate(new Date('June 1, 2079')); + TYPES.SmallDateTime.validate(new Date('June 7, 2079')); }, TypeError, 'Out of range.'); }); });