Skip to content

Error with YYYY in date-fns v2 #1767

@billygl

Description

@billygl

Expected behavior

Working as expected.

Actual behavior

Errors:
index.js:14 Uncaught RangeError: Use yyyy instead of YYYY for formating years; see: https://git.io/fxCyr

Steps to reproduce

npm install react-datepicker --save
npm install --save @types/react-datepicker
  • in the first installation, it says:
    date-fns

node ./docs/printV2Notice.js
Thank you for testing (⩗) date-fns v2!
In v2 we've introduced a number of breaking changes
that make date-fns even more consistent and reliable.
Please read the changelog carefully: https://git.io/fxCWb

  • in package.json from react-datepicker
  "dependencies": {
    "classnames": "^2.2.5",
    "date-fns": "^2.0.0-alpha.23"

solution

  • in index.js from react-datepicker change YYYY to yyyy

Month.prototype.render = function render() {
    var showMonthYearPicker = this.props.showMonthYearPicker;

    return React.createElement(
      "div",
      {
        className: this.getClassNames(),
        onMouseLeave: this.handleMouseLeave,
        role: "listbox",
        "aria-label": "month-" + formatDate(this.props.day, "yyyy-MM")
      },
      showMonthYearPicker ? this.renderMonths() : this.renderWeeks()
    );
  };

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions