refactor(extension): consolidate 5 relativeTime copies into shared util
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
import { getState, setState, sendMessage, navigate, escapeHtml } from '../../shared/state';
|
||||
import type { ItemId, ManifestEntry, VaultSettings } from '../../shared/types';
|
||||
import { relativeTime, daysUntilPurge } from '../../shared/relative-time';
|
||||
import {
|
||||
GLYPH_TYPE_LOGIN, GLYPH_TYPE_SECURE_NOTE, GLYPH_TYPE_IDENTITY, GLYPH_TYPE_CARD,
|
||||
GLYPH_TYPE_KEY, GLYPH_TYPE_DOCUMENT, GLYPH_TYPE_TOTP,
|
||||
@@ -17,21 +18,6 @@ const TYPE_ICONS: Record<string, string> = {
|
||||
totp: GLYPH_TYPE_TOTP,
|
||||
};
|
||||
|
||||
function relativeTime(unixSec: number): string {
|
||||
const now = Math.floor(Date.now() / 1000);
|
||||
const diff = now - unixSec;
|
||||
if (diff < 60) return 'just now';
|
||||
if (diff < 3600) return `${Math.floor(diff / 60)}m ago`;
|
||||
if (diff < 86400) return `${Math.floor(diff / 3600)}h ago`;
|
||||
return `${Math.floor(diff / 86400)}d ago`;
|
||||
}
|
||||
|
||||
function daysUntilPurge(trashedAt: number, retention: VaultSettings['trash_retention']): number | null {
|
||||
if (retention.kind === 'forever') return null;
|
||||
const trashedDaysAgo = Math.floor((Date.now() / 1000 - trashedAt) / 86400);
|
||||
return Math.max(0, retention.value - trashedDaysAgo);
|
||||
}
|
||||
|
||||
export function teardown(): void {
|
||||
// No cleanup needed
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user