Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript: import formatDate and parseDate from react-day-picker/moment #895

Conversation

singingwolfboy
Copy link
Contributor

This allows TypeScript to understand the following import:

import MomentLocaleUtils, {
  formatDate,
  parseDate,
} from 'react-day-picker/moment';

as specified in the documentation.

@codecov-io
Copy link

codecov-io commented Apr 16, 2019

Codecov Report

Merging #895 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #895   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          15     15           
  Lines         659    659           
  Branches      146    146           
=====================================
  Hits          659    659

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 421af9f...83234f0. Read the comment docs.

@fivetwelve
Copy link

I wonder if this has something to do with the following issue I am having (using v7.3.0)?

When trying to call formatDate(selectedDay, 'LL', myLocale) where I've tried equating myLocale to 'en' and 'en-us', I get a deprecation warning. However, if I call formatDate(selectedDay, 'LL', 'en'), there is no warning. Not ideal since I need to support multiple locales and prefer not to (and shouldn't have to) hardcode the locale.

Warning is:
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.

@fivetwelve
Copy link

fivetwelve commented Apr 23, 2019

Not sure I understand why this works since the function funnels over to moment functions but this seemed to work for me and avoided displaying any warnings:

formatDate(new Date(yourDate), 'LL', yourLocale).

It didn't matter that my date string was moment-compatible. I tried the date returned by react-day-picker as well as a string that moment could parse such as '2019 July'. In any case, I hope my workaround is forward-compatible.

@singingwolfboy
Copy link
Contributor Author

@fivetwelve this change only affects the TypeScript compiler. It has no effect on how the JavaScript in this project runs. If you are getting a deprecation warning, that is from JavaScript, not from the TypeScript compiler.

@qbolt
Copy link

qbolt commented Apr 30, 2019

I could really use this! Hope it gets merged soon.

@MartinNuc
Copy link

any news regarding this PR?

@gpbl
Copy link
Owner

gpbl commented Aug 3, 2019

Is this fixed via #899?

@gpbl
Copy link
Owner

gpbl commented Oct 17, 2019

Closing as seems fixed. Please reopen if needed, thanks!

@gpbl gpbl closed this Oct 17, 2019
@davidpmccormick
Copy link

I'm seeing this issue with version 7.4.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants