Skip to content

Commit 85e448e

Browse files
authored
fix(clerk-js): Update shortDate modifier to include year for future dates (#5707)
1 parent 110f8dd commit 85e448e

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

.changeset/ten-taxes-float.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/clerk-js': patch
3+
---
4+
5+
Update shortDate modifier to include year for future dates.

packages/clerk-js/src/ui/localization/localizationModifiers.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,17 @@ const weekday = (val: Date | string | number, locale?: string, weekday?: 'long'
1919
}
2020
};
2121

22+
/**
23+
* Returns a short date string if the current year is the same as the date's year,
24+
* otherwise returns a long date string.
25+
*/
2226
const shortDate = (val: Date | string | number, locale?: string) => {
27+
const date = normalizeDate(val);
2328
try {
2429
return new Intl.DateTimeFormat(locale || 'en-US', {
2530
month: 'short',
2631
day: 'numeric',
32+
...(date.getFullYear() !== new Date().getFullYear() ? { year: 'numeric' } : {}),
2733
}).format(normalizeDate(val));
2834
} catch (e) {
2935
console.warn(e);

0 commit comments

Comments
 (0)