fix: custom relative time to shorten strings for better UI fit

This commit is contained in:
Dries Augustyns
2025-12-11 11:13:39 +01:00
parent 1019ba0d82
commit 5e4adb71ad
6 changed files with 35 additions and 10 deletions
+20
View File
@@ -2,6 +2,8 @@
* Shared date formatting and manipulation utilities
*/
import dayjs from 'dayjs';
/**
* Get the user's timezone
*/
@@ -106,3 +108,21 @@ export function formatUTCDateTime(date: Date): string {
timeZone: 'UTC',
});
}
/**
* Format a date as relative time with short format for very recent updates
* Returns "just now" for updates within the last minute to avoid text wrapping
*/
export function formatRelativeTime(date: Date | string): string {
const now = dayjs();
const then = dayjs(date);
const secondsAgo = now.diff(then, 'second');
// If less than 60 seconds, show "just now"
if (secondsAgo < 60) {
return 'just now';
}
// Otherwise use standard relative time
return then.fromNow();
}