fix(version): 修正概览耗时与排名统计
This commit is contained in:
@@ -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 '0h(0天)';
|
||||
return `${hours}h(${formatNaturalDays(hours)})`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 仅天数版:"Y天"
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user