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

Add formatDate and parseDate to typings #873

Merged
merged 2 commits into from
Oct 17, 2019
Merged

Conversation

no23reason
Copy link
Contributor

The formatDate and parseDate are not mentioned in the typings for LocaleUtils although they contain them. This means the code in the example:

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

ends up with an error in TypeScript. If this is merged, this code could be replaced by

import MomentLocaleUtils from 'react-day-picker/moment';
// MomentLocaleUtils contains formatDate and parseDate even in TypeScript

@codecov
Copy link

codecov bot commented Feb 27, 2019

Codecov Report

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

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #873   +/-   ##
=====================================
  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 b086617...921b376. Read the comment docs.

3 similar comments
@codecov
Copy link

codecov bot commented Feb 27, 2019

Codecov Report

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

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #873   +/-   ##
=====================================
  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 b086617...921b376. Read the comment docs.

@codecov
Copy link

codecov bot commented Feb 27, 2019

Codecov Report

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

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #873   +/-   ##
=====================================
  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 b086617...921b376. Read the comment docs.

@codecov
Copy link

codecov bot commented Feb 27, 2019

Codecov Report

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

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #873   +/-   ##
=====================================
  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 b086617...921b376. Read the comment docs.

@lukewis
Copy link

lukewis commented Mar 13, 2019

It seems that this "worked" in v7.2.4, but broke with v7.3.0

@undrivendev
Copy link

You declared the formatDate signature as:
formatDate(date: Date, format?: string | string[], locale?: string): string;
But given that the moment.js 'string + format' method signature declares the format to be a string and not a string[], shouldn't you change it to:
formatDate(date: Date, format?: string, locale?: string): string; .
Also, the method parseDate can also return undefined, so the return type should be changed to Date | undefined .. IMO

@singingwolfboy
Copy link
Contributor

formatDate and parseDate are not exported in the LocaleUtils file. They are exported in the MomentLocaleUtils file, however. I made a different pull request (#895) that reflects this situation more accurately.

@gpbl
Copy link
Owner

gpbl commented Aug 3, 2019

Is this fixed via #899?

@estephinson
Copy link

estephinson commented Aug 19, 2019

Is this fixed via #899?

I would say not, in #899 there is no change to the typings, purely refactoring, the issue is purely formatDate and parseDate are not exposed. Correct me if I'm wrong, but there is no change in #899 to include formatDate and parseDate?

@estephinson
Copy link

Current workaround for me is to simply define the functions in the project yourself, as thankfully they're relatively simple:

function formatDate(date, format = 'L', locale = 'en') {
    return moment(date)
        .locale(locale)
        .format(Array.isArray(format) ? format[0] : format);
}

function parseDate(str, format = 'L', locale = 'en') {
    const m = moment(str, format, locale, true);
    if (m.isValid()) {
        return m.toDate();
    }
    return undefined;
}

@gpbl gpbl added this to the v7.2.0 milestone Oct 17, 2019
@gpbl gpbl merged commit 28c4282 into gpbl:master Oct 17, 2019
kimamula pushed a commit to kimamula/react-day-picker that referenced this pull request Aug 17, 2022
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

6 participants