refactor(extension): consolidate 5 relativeTime copies into shared util

This commit is contained in:
adlee-was-taken
2026-05-24 18:28:21 -04:00
parent 9da45dd478
commit a587965528
5 changed files with 5 additions and 55 deletions

View File

@@ -10,6 +10,7 @@ import type {
} from '../shared/types';
import { registerHost } from '../shared/state';
import { lookupErrorCopy, type ErrorCta } from '../shared/error-copy';
import { relativeTime } from '../shared/relative-time';
import {
GLYPH_TRASH, GLYPH_DEVICES, GLYPH_SETTINGS, GLYPH_LOCK,
GLYPH_TYPE_LOGIN, GLYPH_TYPE_SECURE_NOTE, GLYPH_TYPE_TOTP,
@@ -122,14 +123,6 @@ function typeLabel(t: ItemType): string {
return labels[t];
}
function relativeTime(unixSec: number): string {
const diffS = Math.floor(Date.now() / 1000) - unixSec;
if (diffS < 60) return 'just now';
if (diffS < 3600) return `${Math.floor(diffS / 60)}m ago`;
if (diffS < 86400) return `${Math.floor(diffS / 3600)}h ago`;
return `${Math.floor(diffS / 86400)}d ago`;
}
// ---------------------------------------------------------------------------
// Hash routing
// ---------------------------------------------------------------------------