Skip to content

Commit b114567

Browse files
committed
fix(formatRelativeTime): prevent "yesterday" from showing for same-day timestamps
1 parent 1384e5d commit b114567

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

frontend/src/utils/format.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ export function formatRelativeTime(d: string | number) {
1818
const now = Date.now()
1919
const diffMs = date.getTime() - now
2020

21+
const isSameDay = formatDate(d, 'YYYY-MM-DD') === formatDate(now, 'YYYY-MM-DD')
22+
2123
// now
2224
if (diffMs === 0) return formatter.format(0, 'second')
2325

@@ -31,6 +33,7 @@ export function formatRelativeTime(d: string | number) {
3133
]
3234

3335
for (const { unit, threshold } of units) {
36+
if (unit === 'day' && isSameDay) continue
3437
const amount = Math.round(diffMs / threshold)
3538
if (Math.abs(amount) > 0) return formatter.format(amount, unit)
3639
}

0 commit comments

Comments
 (0)