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

deps: Upgrade date-fns to v2.29.3 #2522

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

Conversation

taratatach
Copy link
Member

@taratatach taratatach commented Oct 11, 2022

We want to use the add and sub functions that are not available
in v1.30.1.

Since there's a large gap between the two versions, we have a lot of
modifications to accommodate API changes:

  • imports of functions whose names are made of multiple words have
    changed from a snake case format to a camel case one
  • locales are not exposed as separate modules anymore; they need to be
    imported from date-fns/locales
  • the format used by format() and parse() is now based on Unicode
    Technical Standard n°35 (see https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table)
    with a few additions (see https://date-fns.org/v2.29.3/docs/format)
    YYYY becomes yyyy
    D becomes d
    DD becomes dd
    ddd becomes EEE
    → the escape character is now ' (single quote) instead of [
  • all date-fns functions now require arguments to be Date objects
    or numbers and do not accept strings anymore. Therefore, all
    date strings are now parsed before being passed as date-fns
    function arguments and all test data mocks have been updated to use
    only ISO formatted date strings
  • isWithinRange becomes isWithinInterval which is inclusive
    (i.e. isWithinRange(3, 1, 3) === false vs
    isWithinInterval(3, { start: 1, end: 3 }) === true)
### ✨ Features

*

### 🐛 Bug Fixes

*

### 🔧 Tech

* Upgrade `date-fns` to v2.29.3 and accommodate API changes.

  We want to use the `add` and `sub` functions that are not available
  in v1.30.1.

  Since there's a large gap between the two versions, we have a lot of
  modifications to accomodate API changes:
  - imports of functions whose names are made of multiple words have
    changed from a snake case format to a camel case one
  - locales are not exposed as separate modules anymore; they need to be
    imported from `date-fns/locales`
  - the format used by `format()` and `parse()` is now based on Unicode
    Technical Standard #35 (see https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table)
    with a few additions (see https://date-fns.org/v2.29.3/docs/format)
    → `YYYY` becomes `yyyy`
    → `D` becomes `d`
    → `DD` becomes `dd`
    → `ddd` becomes `EEE`
    → the escape character is now `'` (single quote) instead of `[`
  - all `date-fns` functions now require arguments to be `Date` objects
    or numbers and do not accept strings anymore. Therefore, all
    date strings are now parsed before being passed as `date-fns`
    function arguments and all test data mocks have been updated to use
    only ISO formatted date strings
  - `isWithinRange` becomes `isWithinInterval` which is inclusive
    (i.e. `isWithinRange(3, 1, 3) === false` vs
    `isWithinInterval(3, { start: 1, end: 3 }) === true`)
@taratatach
Copy link
Member Author

This PR is waiting for other libraries to upgrade date-fns (e.g. cozy-ui) as we deduplicate libs and the new version of date-fns is incompatible with the old one used in our own libs.

Base automatically changed from fix/prevent-excessive-konnector-alerts-notifications to master October 12, 2022 07:43
import frLocale from 'date-fns/locale/fr'
import enLocale from 'date-fns/locale/en'
import esLocale from 'date-fns/locale/es'
import { fr as frLocale, en as enLocale, es as esLocale } from 'date-fns/locale'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This version of date-fns does not export any en locale anymore. You likely want enUS instead.

@PolariTOON
Copy link
Contributor

We have a webpack config in this app that defines a ContextReplacementPlugin for date-fns locales. The regexp should likely be changed from /(en|fr|es)\/index\.js/ to /(en-US|fr|es)\/index\.js/.

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.

2 participants