Material-ui-pickers: moment.js deprecation warning using date-io/moment

Created on 22 Jun 2020  路  9Comments  路  Source: mui-org/material-ui-pickers

Environment

| Tech | Version |
| -------------------- | ------- |
| @material-ui/pickers | 3.2.10 |
| material-ui | 4.10.2 (core) |
| TypeScript | |
| React | 16.13.1 |
| Browser | Google Chrome 83.0.4103.106 (Official Build) (64-bit) |
| Peer library | moment 2.26.0, date-io/moment 1.3.13 |

Steps to reproduce

  1. Start with a null selectedDate
  2. Open the date picker
  3. Choose a date

Expected behavior

No warnings.

Actual behavior

The following warning:

Deprecation warning: value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are discouraged and will be removed in an upcoming major release. Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info.
Arguments: 
[0] _isAMomentObject: true, _isUTC: false, _useUTC: false, _l: undefined, _i: 06/22/2020, _f: undefined, _strict: undefined, _locale: [object Object]

Live example

https://codesandbox.io/s/nifty-kare-4xeum?fontsize=14&hidenavigation=1&theme=dark

bug 馃悰 important

Most helpful comment

I just updated my code base and the live example to use more current versions of dependencies:

| Tech | Version |
| -------------------- | ------- |
| @material-ui/pickers | 4.0.0-alpha.10 |
| material-ui | 4.10.2 (core) |
| TypeScript | |
| React | 16.13.1 |
| Browser | Google Chrome 83.0.4103.106 (Official Build) (64-bit) |
| Peer library | moment 2.27.0, date-io/moment 1.3.13 |

All 9 comments

i am facing the same issue too but with KeyboardDatePicker

+1

We do no longer support v3, please provide a reproduction with v4.0.0-alpha.10. This would help a lot 馃懛 .
A live example would be perfect. This codesandbox.io template _may_ be a good starting point. Thank you!

It is reproducing and we know it. Thats why we have disabled warning failure on CI for moment tests

I just updated my code base and the live example to use more current versions of dependencies:

| Tech | Version |
| -------------------- | ------- |
| @material-ui/pickers | 4.0.0-alpha.10 |
| material-ui | 4.10.2 (core) |
| TypeScript | |
| React | 16.13.1 |
| Browser | Google Chrome 83.0.4103.106 (Official Build) (64-bit) |
| Peer library | moment 2.27.0, date-io/moment 1.3.13 |

Here's the link to a new live example with the updated dependencies:

https://codesandbox.io/s/weathered-feather-fhnhh?file=/src/App.jsx

@mjburtenshaw Any idea how we could solve this problem?

@oliviertassinari I'll take a look through the moment.js docs as I have time through this week to see what we can do. I'll provide an update on Friday at end-of-business with my findings if I don't think of any solutions sooner.

I took a deeper look at the warning details, and I think that the date string being passed to the MomentAdapter is in MM/DD/YYYY format, which is an unreliable format according to moment.js:

image

Changing the date string being passed to the MomentAdapter to one of the following may fix it:

  • moment("2014-04-25T01:32:21.196Z"); // iso string, utc timezone
  • moment("2014-04-25T01:32:21.196+0600"); // iso string with timezone
  • moment("2014 04 25", "YYYY MM DD"); // string with format

But, I'm not certain if that's something that needs to be tested in material-ui/pickers or if that's something that's managed by date-io/moment.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

idrm picture idrm  路  3Comments

benneq picture benneq  路  3Comments

sakulstra picture sakulstra  路  3Comments

basselAhmed picture basselAhmed  路  3Comments

aditya81070 picture aditya81070  路  3Comments