Skip to content

DayJS parses wrong year value for the date "0001-01-01" #1237

Description

@matheusot

Describe the bug
When trying to parse the dates "0000-01-01" and "0001-01-01" DayJS returns the years 1900 and 1901 respectively:

const dayjs = require('dayjs')
console.log(dayjs("0001-01-01", "YYYY-MM-DD"))

Output:

d {
  '$L': 'en',
  '$d': 1901-01-01T03:06:28.000Z,
  '$x': {},
  '$y': 1901,
  '$M': 0,
  '$D': 1,
  '$W': 2,
  '$H': 0,
  '$m': 0,
  '$s': 0,
  '$ms': 0
}

Expected behavior
The expected behavior is that the returned object has the correct year. Setting the year manually we can see the correct behavior working:

const dayjs = require('dayjs')
console.log(dayjs("2020-01-01", "YYYY-MM-DD").year(1))

Output:

d {
  '$L': 'en',
  '$d': 0001-01-01T03:06:28.000Z,
  '$x': {},
  '$y': 1,
  '$M': 0,
  '$D': 1,
  '$W': 1,
  '$H': 0,
  '$m': 0,
  '$s': 0,
  '$ms': 0
}

Information

  • Day.js Version v1.9.6
  • OS: Windows
  • Browser: N/A (Node.js v12.18.3)
  • Time zone: GMT-03:00

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions