Skip to content

Commit

Permalink
change datetime range check
Browse files Browse the repository at this point in the history
  • Loading branch information
mShan0 committed Feb 7, 2024
1 parent ecc7fb3 commit 9452e06
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/data-types/datetime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ const EPOCH_DATE = LocalDate.ofYearDay(1900, 1);
const NULL_LENGTH = Buffer.from([0x00]);
const DATA_LENGTH = Buffer.from([0x08]);

const MIN_DATE = new Date('January 1, 1753');
const MAX_DATE = new Date('December 31, 9999');

const DateTime: DataType = {
id: 0x3D,
type: 'DATETIME',
Expand Down Expand Up @@ -88,11 +85,14 @@ const DateTime: DataType = {

// TODO: check date range: January 1, 1753, through December 31, 9999
// : time range: 00:00:00 through 23:59:59.997
let year;
if (options && options.useUTC) {
value = new Date(value.toUTCString());
year = value.getUTCFullYear();
} else {
year = value.getFullYear();
}

if (value < MIN_DATE || value > MAX_DATE) {
if (year < 1753 || year > 9999) {
throw new TypeError('Out of range.');
}

Expand Down

0 comments on commit 9452e06

Please sign in to comment.