refactor(extension): consolidate 5 relativeTime copies into shared util
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
import { setState, sendMessage, navigate, escapeHtml } from '../../shared/state';
|
||||
import type { Device } from '../../shared/types';
|
||||
import { relativeTime } from '../../shared/relative-time';
|
||||
|
||||
interface RevokedEntry {
|
||||
name: string;
|
||||
@@ -10,16 +11,6 @@ interface RevokedEntry {
|
||||
revoked_by: string;
|
||||
}
|
||||
|
||||
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`;
|
||||
if (diff < 2592000) return `${Math.floor(diff / 86400)}d ago`;
|
||||
return `${Math.floor(diff / 2592000)}mo ago`;
|
||||
}
|
||||
|
||||
function detectDefaultDeviceName(): string {
|
||||
const ua = navigator.userAgent ?? '';
|
||||
const platform = (navigator.platform ?? '').toLowerCase();
|
||||
|
||||
Reference in New Issue
Block a user