mirror of
https://github.com/tiennm99/ccs.git
synced 2026-09-04 02:17:49 +00:00
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
This commit is contained in:
@@ -6,6 +6,9 @@
|
||||
// UI utilities (main export)
|
||||
export * from './ui';
|
||||
|
||||
// Time utilities
|
||||
export * from './time';
|
||||
|
||||
// Shell execution
|
||||
export { execClaude, escapeShellArg } from './shell-executor';
|
||||
|
||||
|
||||
@@ -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';
|
||||
}
|
||||
Reference in New Issue
Block a user