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

Update date-fns to 2.29.3 #2310

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

PolariTOON
Copy link
Contributor

@PolariTOON PolariTOON commented Dec 9, 2022

This is a major update of date-fns which brings breaking changes that will affect libs and apps consuming Cozy UI.

@bundlemon
Copy link

bundlemon bot commented Dec 9, 2022

BundleMon

Unchanged files (2)
Status Path Size Limits
dist/cozy-ui.min.css
19.67KB +5%
dist/cozy-ui.utils.min.css
9.99KB +5%

No change in files bundle size

Groups updated (1)
Status Path Size Limits
transpiled/react/**
551.41KB (+63B +0.01%) -

Final result: ✅

View report in BundleMon website ➡️


Current branch size history | Target branch size history

@@ -22,7 +22,7 @@ const DumbHelloWorld = translate()(({ t, f, lang }) => (
<div>
{t('helloworld')}
<br />
{f('2020-01-06', 'DDD MMM')}
{f(new Date('2020-01-06'), 'd MMM')}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't, f deal with this BC by itself? It it's a string, then create a new Date() by itself? In order to help the migration.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, is there any codemods that are helping to convert old date notation (ex DDD MMM) to the new one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is this table in the changelog of the lib that compares the old pattern with the new pattern : https://github.com/date-fns/date-fns/blob/main/CHANGELOG.md#200---2019-08-20 . There are sometimes multiple way to convert the pattern, depending on what we really expect.


const getWarningMessage = lang =>
`The "${lang}" locale isn't supported by date-fns. or has not been included in the build. Check if you have configured a ContextReplacementPlugin that is too restrictive.`

export const provideDateFnsLocale = (userLang, defaultLang = DEFAULT_LANG) => {
lang = userLang
const resolvedDefaultLang = defaultLang === 'en' ? 'en-US' : defaultLang
const resolvedUserLang = userLang === 'en' ? 'en-US' : userLang
Copy link
Contributor

Choose a reason for hiding this comment

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

This should also be done for fr-FR, right? And also es-ES since these are the 3 supported langages

Copy link
Contributor Author

Choose a reason for hiding this comment

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

French and Spanish localizations have not been moved. They are still in fr and es directory and fr-FR and es-ES do not exist, so we should not change anything for them.

}
}
lang = resolvedUserLang
return locales[lang]
}

Copy link
Contributor

Choose a reason for hiding this comment

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

It also means that the consuming app should change the call to <I18n to pass the right ISO code. Today this call is based on what the stack / flagship are injecting. For instance https://github.com/cozy/mespapiers/blob/48b5ec048b00d29c418f06606cc9ec15c2a203c7/src/targets/browser/setupApp.jsx#L15

@PolariTOON PolariTOON force-pushed the feat/add-format-locally-distance-to-now-strict branch from 01ea93c to cba770f Compare December 13, 2022 09:21
@PolariTOON PolariTOON marked this pull request as draft December 19, 2022 18:47
@PolariTOON PolariTOON changed the title Add formatLocallyDistanceToNowStrict Update date-fns to 2.29.3 Dec 19, 2022
@PolariTOON PolariTOON force-pushed the feat/add-format-locally-distance-to-now-strict branch 2 times, most recently from f83bcff to 1429f3c Compare December 21, 2022 10:53
BREAKING CHANGE: This change expectations on arguments
passed to the `f` function returned by the `useI18n` hook.
The first one now should be a `Date` object instead of a string and
the second one now needs to conform to Unicode Technical Report 35.
`date-fns` does not export any `en` folder anymore, but apps
still rely on it via the `I18n` component.
We allow them to use either `en` or `en-US` as a locale identifier.
This should help consuming libs and apps to migrate.
`date-fns` functions do not accept dates formatted as strings anymore, but only date objects.
We make it so the `f` function returned by the `useI18n` hook still accepts other types of values, strings in particular.
This should help consuming libs and apps to migrate.
@PolariTOON PolariTOON force-pushed the feat/add-format-locally-distance-to-now-strict branch from 1429f3c to 0abfcc7 Compare December 22, 2022 08:54
@PolariTOON PolariTOON marked this pull request as ready for review December 22, 2022 09:14
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