Skip to content

Commit

Permalink
fix: Accept any type of date in the f function
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
PolariTOON committed Dec 13, 2022
1 parent 347bb5e commit 9bf0223
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion react/I18n/format.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ export const initFormat = (userLang, defaultLang = DEFAULT_LANG) => (
date,
formatStr
) => {
const dateObject = new Date(date)
const locale = provideDateFnsLocale(userLang, defaultLang)
return format(date, formatStr, { locale })
return format(dateObject, formatStr, { locale })
}

export const formatLocallyDistanceToNow = date =>
Expand Down

0 comments on commit 9bf0223

Please sign in to comment.