Open
Description
- What versions are you using?
6.0.0 - Is it an error or a hang or a crash?
error - What error(s) or behavior you are seeing?
Dates with a year from 1 to 100 are returned as 19xx - Include a runnable Node.js script that shows the problem.
const years = [
9999,
2023,
1000,
100,
10,
1,
-1,
-10,
-100
-1000,
];
const sql = `SELECT ${years.map(year => `DATE '${year}-01-01'`).join(', ')} FROM DUAL`;
const {rows: [row]} = await conn.execute(sql);
deepEqual(years, row.map(d=>d.getFullYear()));
The reason is related to the behavior of the Date constructor.
Values from 0 to 99 map to the years 1900 to 1999.
Patch for _makeDate
method in lib/settings.js
:
if (useLocal) {
const d = new Date(year, month - 1, day, hour, minute, second, fseconds);
if (0 < year < 100) {
d.setFullYear(year);
}
return d;
}