next-intl
next-intl copied to clipboard
Support Intl.RelativeTimeFormat for `relativeTime` formatting
Is your feature request related to a problem? Please describe.
Currently, the formatter for Formatting date and time ranges does not support additional configuration other than specifying the exact unit to display the output in.
The relative time formatting should support all the options from Intl.RelativeTimeFormat and not just RelativeTimeFormatUnit
Describe the solution you'd like
Instead of:
type RelativeTimeFormatOptions = {
now?: number | Date;
unit?: Intl.RelativeTimeFormatUnit;
};
export default RelativeTimeFormatOptions;
The RelativeTimeFormatOptions type should also accept the options from the Intl.RelativeTimeFormat constructor:
- numberingSystem
- style
- numeric
Describe alternatives you've considered
The only alternative would be to use the native Intl API directly, but this should be integrated into the formatter in next-intl IMO
Hey, thanks for the report! I agree, we could definitely support numberingSystem and style.
As for numeric I'm a bit hesitant though, as it can lead to issues when values are rounded: https://github.com/amannn/next-intl/pull/765.
See also:
https://github.com/amannn/next-intl/blob/3eefe6f5f12b49ca0237c96ac84a1abdce6dbab3/packages/use-intl/src/core/createFormatter.tsx#L247-L257
Do you need numeric for your use case? If so, can you include further details?
I've added #1057 to look into this.
At the moment, I only have a need for the style to specify long, short, or narrow.
I think numberingSystem and style is sufficient for now!
Sounds good, thanks for the feedback!