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

Created on 17 Jun 2019  路  6Comments  路  Source: Hacker0x01/react-datepicker

https://github.com/Hacker0x01/react-datepicker/issues/1767

  • Issue still persists in 2.7.0 from clean node_modules install
wontfix

Most helpful comment

Problem persists in 2.8.0. This error makes this library unusable until it's fixed. 鈽狅笍
Error: RangeError: Use yyyy instead of YYYY for formating years

All 6 comments

+1

This problem is particularly annoying

It's rarely good to use an alpha version (date-fns v2.alpha https://github.com/Hacker0x01/react-datepicker/blob/master/package.json#L103)

@Darrken It wasn't possible to use the 1.x version of date-fns? (which would accept those older date formats, they are maybe non-standard but it helps a lot for a smoother transition, we have a lot of those date formats in DB, we can't migrate them all at once)

I'm trying with something hacky like this, but as you can see it's fragile:

// https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
// converts from moment which use non-standard formats, to date-fns use https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
const fixDateFns2Format = format => format
  .replace('YYYY', 'yyyy') // full year
  .replace(/\bDD\b/, 'dd') // day of month, short
  .replace('dddd', 'cccc'); // day of week, long

Problem persists in 2.8.0. This error makes this library unusable until it's fixed. 鈽狅笍
Error: RangeError: Use yyyy instead of YYYY for formating years

+1

For now I ought to use the 2.4.... version of this package

+1
Still a problem in version 2.9.6
version 2.4.0 works as intended

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tamitutor picture tamitutor  路  3Comments

ericreis picture ericreis  路  3Comments

sarav1234 picture sarav1234  路  3Comments

ahribori picture ahribori  路  3Comments

ro-savage picture ro-savage  路  3Comments