mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-21 01:07:46 +00:00
41 lines
891 B
TypeScript
41 lines
891 B
TypeScript
/**
|
|
* @license
|
|
* Copyright 2025 Qwen Team
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
/**
|
|
* Time ago formatter (matching Claude Code)
|
|
*
|
|
* @param timestamp - ISO timestamp string
|
|
* @returns Formatted time string
|
|
*/
|
|
export const getTimeAgo = (timestamp: string): string => {
|
|
if (!timestamp) {
|
|
return '';
|
|
}
|
|
const now = new Date().getTime();
|
|
const then = new Date(timestamp).getTime();
|
|
const diffMs = now - then;
|
|
const diffMins = Math.floor(diffMs / 60000);
|
|
const diffHours = Math.floor(diffMs / 3600000);
|
|
const diffDays = Math.floor(diffMs / 86400000);
|
|
|
|
if (diffMins < 1) {
|
|
return 'now';
|
|
}
|
|
if (diffMins < 60) {
|
|
return `${diffMins}m`;
|
|
}
|
|
if (diffHours < 24) {
|
|
return `${diffHours}h`;
|
|
}
|
|
if (diffDays === 1) {
|
|
return 'Yesterday';
|
|
}
|
|
if (diffDays < 7) {
|
|
return `${diffDays}d`;
|
|
}
|
|
return new Date(timestamp).toLocaleDateString();
|
|
};
|