diff --git a/.changeset/ten-taxes-float.md b/.changeset/ten-taxes-float.md new file mode 100644 index 00000000000..7a2e0b3054f --- /dev/null +++ b/.changeset/ten-taxes-float.md @@ -0,0 +1,5 @@ +--- +'@clerk/clerk-js': patch +--- + +Update shortDate modifier to include year for future dates. diff --git a/packages/clerk-js/src/ui/localization/localizationModifiers.ts b/packages/clerk-js/src/ui/localization/localizationModifiers.ts index 2a8c6e581cd..32455ac1407 100644 --- a/packages/clerk-js/src/ui/localization/localizationModifiers.ts +++ b/packages/clerk-js/src/ui/localization/localizationModifiers.ts @@ -19,11 +19,17 @@ const weekday = (val: Date | string | number, locale?: string, weekday?: 'long' } }; +/** + * Returns a short date string if the current year is the same as the date's year, + * otherwise returns a long date string. + */ const shortDate = (val: Date | string | number, locale?: string) => { + const date = normalizeDate(val); try { return new Intl.DateTimeFormat(locale || 'en-US', { month: 'short', day: 'numeric', + ...(date.getFullYear() !== new Date().getFullYear() ? { year: 'numeric' } : {}), }).format(normalizeDate(val)); } catch (e) { console.warn(e);