fix: 实际耗时改为精确时间戳计算(精确到0.5h)
之前用日期+工作日×8h 计算耗时太粗糙,现改为: - DevTask startDate/completedAt 使用完整 ISO 时间戳(含时分秒) - TestCase startedAt/completedAt 同上 - 耗时 = (endTimestamp - startTimestamp) / 3600000,精确到0.5h - 详情抽屉显示精确到分钟的时间(YYYY-MM-DD HH:mm) 例如:08:00 开始,10:30 提测,耗时 2.5h(不再是8h) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -83,18 +83,12 @@ export function formatHours(hours: number): string {
|
||||
|
||||
export function calcActualHoursByDates(startDate?: string, completedAt?: string): number {
|
||||
if (!startDate) return 0;
|
||||
const end = completedAt || new Date().toISOString().slice(0, 10);
|
||||
const start = new Date(startDate);
|
||||
const endDate = new Date(end);
|
||||
if (isNaN(start.getTime()) || isNaN(endDate.getTime()) || endDate < start) return 0;
|
||||
let workDays = 0;
|
||||
const current = new Date(start);
|
||||
while (current <= endDate) {
|
||||
const day = current.getDay();
|
||||
if (day !== 0 && day !== 6) workDays++;
|
||||
current.setDate(current.getDate() + 1);
|
||||
}
|
||||
return workDays * 8;
|
||||
const end = completedAt || new Date().toISOString();
|
||||
const startMs = new Date(startDate).getTime();
|
||||
const endMs = new Date(end).getTime();
|
||||
if (isNaN(startMs) || isNaN(endMs) || endMs < startMs) return 0;
|
||||
const diffHours = (endMs - startMs) / (1000 * 60 * 60);
|
||||
return Math.round(diffHours * 2) / 2; // 精确到0.5h
|
||||
}
|
||||
|
||||
export function generateTaskNo(existingTasks: DevTask[]): string {
|
||||
|
||||
Reference in New Issue
Block a user