React-datepicker: Error with YYYY in date-fns v2

Created on 5 Jun 2019  Â·  5Comments  Â·  Source: Hacker0x01/react-datepicker

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()
    );
  };

All 5 comments

Fixed by #1769

I used to have the same issue a week ago and then it was quickly fixed.
I haven't change anything related to datepicker in my code since then but now I have this issue again.

This issue still persists in 2.7.0

Still seeing this behavior in 2.8.0

~This issue persists in 2.9.6. How is this still an issue? This completely breaks the component in Safari (13.0.2)...~
EDIT: I take that back, looks like it's working after all! Apologies

Was this page helpful?
0 / 5 - 0 ratings