Skip to content

Commit

Permalink
fix: correct SmallDateTime upper bound range (#1621)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Sun <47126816+MichaelSun90@users.noreply.github.com>
  • Loading branch information
rockymadden and MichaelSun90 authored Jun 26, 2024
1 parent 025ef72 commit 1a703e2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/data-types/smalldatetime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}
}
Expand Down
6 changes: 1 addition & 5 deletions test/unit/data-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
});
});
Expand Down

0 comments on commit 1a703e2

Please sign in to comment.