fix(version): 修正概览耗时与排名统计

This commit is contained in:
Script Generator
2026-06-26 13:06:22 +08:00
parent 4cda624dc7
commit dde7a9a623
9 changed files with 857 additions and 367 deletions

View File

@@ -94,6 +94,36 @@ export function formatWorkHoursShort(hours: number): string {
return `${hours}h`;
}
/**
* 计算真实经过时长,而不是工作时段内时长。
*
* 用于“实际耗时”口径:按开始/结束时间戳直接相减,精度 0.5h
* 只要有正向耗时,最低按 0.5h 计,避免 30 分钟内工作被显示为 0。
*/
export function calcActualElapsedHours(startISO?: string | null, endISO?: string | null): number {
if (!startISO || !endISO) return 0;
const start = new Date(startISO).getTime();
const end = new Date(endISO).getTime();
if (isNaN(start) || isNaN(end) || end <= start) return 0;
const hours = (end - start) / MS_PER_HOUR;
return Math.max(0.5, Math.round(hours * 2) / 2);
}
function formatNaturalDays(hours: number): string {
if (!isFinite(hours) || hours <= 0) return '0天';
const days = hours / 24;
if (days < 0.1) return `${Number(days.toFixed(2))}`;
return `${Number.isInteger(days) ? String(days) : days.toFixed(1).replace(/\.0$/, '')}`;
}
/**
* 实际耗时显示,天数按自然日 24h 换算。
*/
export function formatActualDuration(hours: number): string {
if (!isFinite(hours) || hours <= 0) return '0h0天';
return `${hours}h${formatNaturalDays(hours)}`;
}
/**
* 仅天数版:"Y天"
*/