From e1f135a93a77f66947ac95b76017e00a5a750c5f Mon Sep 17 00:00:00 2001 From: kaitranntt Date: Fri, 19 Dec 2025 15:39:40 -0500 Subject: [PATCH] refactor(utils): extract formatRelativeTime to utils/time.ts - create utils/time.ts for centralized time formatting - remove duplicate from auth/commands/types.ts - re-export for backward compatibility - export from utils/index.ts --- src/auth/commands/types.ts | 20 +++----------------- src/utils/index.ts | 3 +++ src/utils/time.ts | 22 ++++++++++++++++++++++ 3 files changed, 28 insertions(+), 17 deletions(-) create mode 100644 src/utils/time.ts diff --git a/src/auth/commands/types.ts b/src/auth/commands/types.ts index 1bb13116..c1346753 100644 --- a/src/auth/commands/types.ts +++ b/src/auth/commands/types.ts @@ -7,6 +7,9 @@ import ProfileRegistry from '../profile-registry'; import { InstanceManager } from '../../management/instance-manager'; +// Re-export for backward compatibility +export { formatRelativeTime } from '../../utils/time'; + /** * Command arguments parsed from CLI */ @@ -61,20 +64,3 @@ export function parseArgs(args: string[]): AuthCommandArgs { yes: args.includes('--yes') || args.includes('-y'), }; } - -/** - * Format relative time (e.g., "2h ago", "1d ago") - */ -export function formatRelativeTime(date: Date): string { - const now = Date.now(); - const diff = now - date.getTime(); - - const minutes = Math.floor(diff / 60000); - const hours = Math.floor(diff / 3600000); - const days = Math.floor(diff / 86400000); - - if (days > 0) return `${days}d ago`; - if (hours > 0) return `${hours}h ago`; - if (minutes > 0) return `${minutes}m ago`; - return 'just now'; -} diff --git a/src/utils/index.ts b/src/utils/index.ts index e8190542..8ecc7329 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -6,6 +6,9 @@ // UI utilities (main export) export * from './ui'; +// Time utilities +export * from './time'; + // Shell execution export { execClaude, escapeShellArg } from './shell-executor'; diff --git a/src/utils/time.ts b/src/utils/time.ts new file mode 100644 index 00000000..a15af9a3 --- /dev/null +++ b/src/utils/time.ts @@ -0,0 +1,22 @@ +/** + * Time Formatting Utilities + * + * Centralized date/time formatting functions. + */ + +/** + * Format relative time (e.g., "2h ago", "1d ago") + */ +export function formatRelativeTime(date: Date): string { + const now = Date.now(); + const diff = now - date.getTime(); + + const minutes = Math.floor(diff / 60000); + const hours = Math.floor(diff / 3600000); + const days = Math.floor(diff / 86400000); + + if (days > 0) return `${days}d ago`; + if (hours > 0) return `${hours}h ago`; + if (minutes > 0) return `${minutes}m ago`; + return 'just now'; +}