export interface VersionPlan { id: string; versionId: string; type: 'research' | 'product' | 'ui'; title: string; owner: string; startTime: string; endTime: string; status: 'pending' | 'in_progress' | 'completed'; linkedRequirementIds?: string[]; resultType?: 'link' | 'file'; resultUrl?: string; resultFileName?: string; resultFileData?: string; remark?: string; overdueReason?: string; createdAt: string; completedAt?: string; addedBy: string; } export type PlanType = VersionPlan['type']; export function calcPlanDuration(start: string, end: string): { days: number; hours: number } { const s = new Date(start).getTime(); const e = new Date(end).getTime(); if (isNaN(s) || isNaN(e) || e <= s) return { days: 0, hours: 0 }; const totalDays = Math.ceil((e - s) / (1000 * 60 * 60 * 24)); return { days: totalDays, hours: totalDays * 8 }; } export function formatDuration(days: number, _hours: number): string { if (days === 0) return '0天'; return `${days}天`; } export function calcTotalDuration(plans: VersionPlan[]): string { const completedOrActive = plans.filter((p) => p.status !== 'pending'); if (completedOrActive.length === 0) return '0天'; const intervals = completedOrActive.map((p) => ({ start: new Date(p.startTime).getTime(), end: p.completedAt ? new Date(p.completedAt).getTime() : new Date(p.endTime).getTime(), })).filter((i) => i.end > i.start).sort((a, b) => a.start - b.start); if (intervals.length === 0) return '0天'; let totalMs = 0; let currentStart = intervals[0].start; let currentEnd = intervals[0].end; for (let i = 1; i < intervals.length; i++) { if (intervals[i].start <= currentEnd) { currentEnd = Math.max(currentEnd, intervals[i].end); } else { totalMs += currentEnd - currentStart; currentStart = intervals[i].start; currentEnd = intervals[i].end; } } totalMs += currentEnd - currentStart; const totalDays = Math.ceil(totalMs / (1000 * 60 * 60 * 24)); return `${totalDays}天`; }