Skip to content

Commit

Permalink
fix(initFormat): Ensure do not crash if no date is passed
Browse files Browse the repository at this point in the history
Since version 115.0.0, the new version of `date-fns`
throws an error if no date has passed.
In order to maintain the same behavior on our apps,
we make sure we don't throw any errors in the apps.
  • Loading branch information
Merkur39 committed Dec 20, 2024
1 parent b37f79d commit 718fd3a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion react/providers/I18n/format.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ export const initFormat =
const locale = provideDateFnsLocale(userLang, defaultLang)
const ensureDate = date && typeof date === 'string' ? new Date(date) : date

return format(ensureDate, formatStr, { locale, ...opts })
try {
return format(ensureDate, formatStr, { locale, ...opts })
} catch (error) {
console.error('Error in initFormat', error)
}
}

export const formatLocallyDistanceToNow = date => {
Expand Down

0 comments on commit 718fd3a

Please sign in to comment.