Skip to content

Commit c49c101

Browse files
committed
Fix relativeTime returning 'in 0 seconds' for just-created log entries
When a log entry is created fractions of a second before display, Math.round(diff) returns 0 and format(0, 'second') produces 'in 0 seconds' rather than 'ago'. Clamp to -1 so entries always display as '1 second ago' when the rounded value is zero. https://claude.ai/code/session_016mM8ccmRQf7mAZQn83oZRS
1 parent 48037d5 commit c49c101

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

src/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ export default {
275275
const diff = (new Date(time).getTime() - Date.now()) / 1000
276276
const abs = Math.abs(diff)
277277
const fmt = new Intl.RelativeTimeFormat('en', { numeric: 'always' })
278-
if (abs < 60) return fmt.format(Math.round(diff), 'second')
278+
if (abs < 60) { const s = Math.round(diff); return fmt.format(s === 0 ? -1 : s, 'second') }
279279
if (abs < 3600) return fmt.format(Math.round(diff / 60), 'minute')
280280
if (abs < 86400) return fmt.format(Math.round(diff / 3600), 'hour')
281281
return fmt.format(Math.round(diff / 86400), 'day')

0 commit comments

Comments
 (0)