Fix options passed to date-fns/parse#4474
Conversation
To provide symmetry with date formatting, also use the special unicode tokens flags on date parsing. See Hacker0x01#4469
There was a problem hiding this comment.
✅ This pull request was sent to the PullRequest network.
@emilecantin you can click here to see the review status or cancel the code review job.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #4474 +/- ##
=======================================
Coverage 95.47% 95.47%
=======================================
Files 29 29
Lines 2518 2518
Branches 1034 1034
=======================================
Hits 2404 2404
Misses 114 114 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
|
|
||
| parsedDate = parse(value, dateFormat, new Date(), { locale: localeObject }); | ||
| parsedDate = parse(value, dateFormat, new Date(), { | ||
| locale: localeObject, |
There was a problem hiding this comment.
If you'd like, and it's not a big deal, we could refactor this object into a const and use it everywhere
https://en.wikipedia.org/wiki/Rule_of_three_(computer_programming)
🔹 Code Reuse (Nice to have)
There was a problem hiding this comment.
Yeah, it's just that sometimes it gets joined with the locale, and sometimes not. We'd have to spread it everywhere ({...object} syntax), which I'm not sure is an improvement. If you think it is, I'll be happy to refactor it that way.
| dateFormat.forEach((df) => { | ||
| let tryParseDate = parse(value, df, new Date(), { | ||
| locale: localeObject, | ||
| useAdditionalWeekYearTokens: true, |
There was a problem hiding this comment.
These come from date-fns, that's how the options are named.
|
@martijnrusschen Is it possible to do another release with these changes? If you were planning on a release this week, I can wait, but this PR does fix a crash that's happening in our app with some specific dateformats that we want to use in our next release. Thanks! |
[](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [react-datepicker](https://togithub.com/Hacker0x01/react-datepicker) | [`^4.14.0` -> `^6.0.0`](https://renovatebot.com/diffs/npm/react-datepicker/4.25.0/6.1.0) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | | [@types/react-datepicker](https://togithub.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/react-datepicker) ([source](https://togithub.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/react-datepicker)) | [`^4.11.2` -> `^6.0.0`](https://renovatebot.com/diffs/npm/@types%2freact-datepicker/4.19.6/6.0.1) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>Hacker0x01/react-datepicker (react-datepicker)</summary> ### [`v6.1.0`](https://togithub.com/Hacker0x01/react-datepicker/releases/tag/v6.1.0): 6.1.0 [Compare Source](https://togithub.com/Hacker0x01/react-datepicker/compare/v6.0.0...v6.1.0) #### What's Changed - Fix - Removed defaultProps from Function Components for React 18.3. by [@​shyk001](https://togithub.com/shyk001) in [https://github.com/Hacker0x01/react-datepicker/pull/4498](https://togithub.com/Hacker0x01/react-datepicker/pull/4498) #### New Contributors - [@​shyk001](https://togithub.com/shyk001) made their first contribution in [https://github.com/Hacker0x01/react-datepicker/pull/4498](https://togithub.com/Hacker0x01/react-datepicker/pull/4498) **Full Changelog**: Hacker0x01/react-datepicker@v6.0.0...v6.1.0 ### [`v6.0.0`](https://togithub.com/Hacker0x01/react-datepicker/releases/tag/v6.0.0): 6.0.0 [Compare Source](https://togithub.com/Hacker0x01/react-datepicker/compare/v5.1.0...v6.0.0) #### What's Changed - Upgrade date-fns to v3 by [@​ethanve](https://togithub.com/ethanve) in [https://github.com/Hacker0x01/react-datepicker/pull/4481](https://togithub.com/Hacker0x01/react-datepicker/pull/4481) - Switch workflows to Node 20 by [@​martijnrusschen](https://togithub.com/martijnrusschen) in [https://github.com/Hacker0x01/react-datepicker/pull/4490](https://togithub.com/Hacker0x01/react-datepicker/pull/4490) #### New Contributors - [@​ethanve](https://togithub.com/ethanve) made their first contribution in [https://github.com/Hacker0x01/react-datepicker/pull/4481](https://togithub.com/Hacker0x01/react-datepicker/pull/4481) **Full Changelog**: Hacker0x01/react-datepicker@v5.1.0...v6.0.0 ### [`v5.1.0`](https://togithub.com/Hacker0x01/react-datepicker/releases/tag/v5.1.0): 5.1.0 [Compare Source](https://togithub.com/Hacker0x01/react-datepicker/compare/v5.0.0...v5.1.0) #### What's Changed - Fix options passed to date-fns/parse by [@​emilecantin](https://togithub.com/emilecantin) in [https://github.com/Hacker0x01/react-datepicker/pull/4474](https://togithub.com/Hacker0x01/react-datepicker/pull/4474) **Full Changelog**: Hacker0x01/react-datepicker@v5.0.0...v5.1.0 ### [`v5.0.0`](https://togithub.com/Hacker0x01/react-datepicker/releases/tag/v5.0.0): 5.0.0 [Compare Source](https://togithub.com/Hacker0x01/react-datepicker/compare/v4.25.0...v5.0.0) #### Breaking changes - Migrate from Popper.js to Floating-UI by [@​G07cha](https://togithub.com/G07cha) in [https://github.com/Hacker0x01/react-datepicker/pull/4393](https://togithub.com/Hacker0x01/react-datepicker/pull/4393) #### What's Changed - 🐛 FIX: readability-isMonthinRange by [@​mary139](https://togithub.com/mary139) in [https://github.com/Hacker0x01/react-datepicker/pull/4421](https://togithub.com/Hacker0x01/react-datepicker/pull/4421) - Fix [#​4431](https://togithub.com/Hacker0x01/react-datepicker/issues/4431): Update the excludedDate to match the year to check of the isYearDisabled by [@​balajis-qb](https://togithub.com/balajis-qb) in [https://github.com/Hacker0x01/react-datepicker/pull/4432](https://togithub.com/Hacker0x01/react-datepicker/pull/4432) - Fix [#​4420](https://togithub.com/Hacker0x01/react-datepicker/issues/4420): Update home key and end key navigation in Calendar component by [@​balajis-qb](https://togithub.com/balajis-qb) in [https://github.com/Hacker0x01/react-datepicker/pull/4430](https://togithub.com/Hacker0x01/react-datepicker/pull/4430) - Document [#​4420](https://togithub.com/Hacker0x01/react-datepicker/issues/4420): 📝 Update the behavior of Home Key and End Key in the README file by [@​balajis-qb](https://togithub.com/balajis-qb) in [https://github.com/Hacker0x01/react-datepicker/pull/4438](https://togithub.com/Hacker0x01/react-datepicker/pull/4438) - Fix [#​4076](https://togithub.com/Hacker0x01/react-datepicker/issues/4076): Trigger onCalendarClose event and onChange even when the same date is selected as the start and the end date in a date range by [@​balajis-qb](https://togithub.com/balajis-qb) in [https://github.com/Hacker0x01/react-datepicker/pull/4394](https://togithub.com/Hacker0x01/react-datepicker/pull/4394) - Excluded dates message by [@​dvelazquez1282](https://togithub.com/dvelazquez1282) in [https://github.com/Hacker0x01/react-datepicker/pull/4437](https://togithub.com/Hacker0x01/react-datepicker/pull/4437) - Fix [#​4456](https://togithub.com/Hacker0x01/react-datepicker/issues/4456): Add shift+pageUp key and shift+pageDown key navigation in Calendar component by [@​balajis-qb](https://togithub.com/balajis-qb) in [https://github.com/Hacker0x01/react-datepicker/pull/4457](https://togithub.com/Hacker0x01/react-datepicker/pull/4457) - Fix options passed to date-fns/format by [@​emilecantin](https://togithub.com/emilecantin) in [https://github.com/Hacker0x01/react-datepicker/pull/4469](https://togithub.com/Hacker0x01/react-datepicker/pull/4469) #### New Contributors - [@​mary139](https://togithub.com/mary139) made their first contribution in [https://github.com/Hacker0x01/react-datepicker/pull/4421](https://togithub.com/Hacker0x01/react-datepicker/pull/4421) - [@​G07cha](https://togithub.com/G07cha) made their first contribution in [https://github.com/Hacker0x01/react-datepicker/pull/4393](https://togithub.com/Hacker0x01/react-datepicker/pull/4393) - [@​dvelazquez1282](https://togithub.com/dvelazquez1282) made their first contribution in [https://github.com/Hacker0x01/react-datepicker/pull/4437](https://togithub.com/Hacker0x01/react-datepicker/pull/4437) - [@​emilecantin](https://togithub.com/emilecantin) made their first contribution in [https://github.com/Hacker0x01/react-datepicker/pull/4469](https://togithub.com/Hacker0x01/react-datepicker/pull/4469) **Full Changelog**: Hacker0x01/react-datepicker@v4.25.0...v5.0.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about these updates again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/ASVGay/the-rhapsodies). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4xNzMuMCIsInVwZGF0ZWRJblZlciI6IjM3LjE3My4wIiwidGFyZ2V0QnJhbmNoIjoiZGV2In0=-->
To provide symmetry with date formatting, also use the special unicode tokens flags on date parsing.
See #4469