feat: update

This commit is contained in:
Rogee
2025-05-08 11:46:57 +08:00
parent 1199118fb4
commit f92429a9c6
6 changed files with 47 additions and 10 deletions

View File

@@ -14,3 +14,24 @@ dayjs.extend(timezone);
export function formatDate(date) {
return dayjs.tz(date, 'Asia/Shanghai').format('YYYY-MM-DD HH:mm:ss');
}
/**
* Format seconds to readable duration string
* @param {number} seconds - Number of seconds
* @returns {string} Formatted duration string (e.g., "2h 30m 15s")
*/
export function formatDuration(seconds) {
if (!seconds || seconds < 0) return '0 秒';
const hours = Math.floor(seconds / 3600);
const minutes = Math.floor((seconds % 3600) / 60);
const remainingSeconds = Math.floor(seconds % 60);
const parts = [];
if (hours > 0) parts.push(`${hours}`);
if (minutes > 0) parts.push(`${minutes}`);
if (remainingSeconds > 0 || parts.length === 0) parts.push(`${remainingSeconds}`);
return parts.join(' ');
}