formatjs / formatjs-old

The monorepo home to all of the FormatJS related libraries.
https://formatjs.io/
156 stars 53 forks source link

How to use Date with intl-relativeformat? #554

Closed rightaway closed 4 years ago

rightaway commented 4 years ago

In 2.1.0 of intl-relativeformat I could do new IntlRelativeFormat('en').format(dateObject) and it would return the correct string based on the date, like 2 hours ago or in 3 years or in 5 minutes.

The package says it's deprecated now at https://www.npmjs.com/package/intl-relativeformat but the examples there don't say how you can use this new version with any Date object the same as the old version. https://github.com/tc39/proposal-intl-relative-time#take-number-instead-of-date-object-for-input says it's not possible.

What's the replacement for the previous functionality if I can't do this with Intl.RelativeTimeFormat? Is sticking with the old version of intl-relativeformat the only option?

longlho commented 4 years ago

You can migrate off that using this https://github.com/formatjs/react-intl/blob/master/docs/Upgrade-Guide.md#formattedrelativetime