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

Open Beginner friendly
#1,570 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
68/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
javascript, node.js
Domain
database

Research direction

Start in lib/settings.js at the _makeDate method and reproduce the reported behavior with the supplied runnable Node.js script. Verify that dates using years from 1 to 100 retain their requested years, while preserving the existing handling for the other listed years.

Written by the indexing model from the issue text.

Description

bug patch available
  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;
}
Dominant language
JavaScript
Stars
2.4k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from oracle/node-oracledb

All issues in oracle/node-oracledb

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.