Skip to content

Dates with a year from 1 to 100 are returned as 19xx #1570

Open
@sla100

Description

@sla100
  1. What versions are you using?
    6.0.0
  2. Is it an error or a hang or a crash?
    error
  3. What error(s) or behavior you are seeing?
    Dates with a year from 1 to 100 are returned as 19xx
  4. 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;
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions