( task: TaskInfo, targetDate: Date )
| 18 | } |
| 19 | |
| 20 | export function buildTimeblockPrefillForTask( |
| 21 | task: TaskInfo, |
| 22 | targetDate: Date |
| 23 | ): TimeblockPrefill { |
| 24 | let startDate: Date | null = null; |
| 25 | |
| 26 | if (task.scheduled) { |
| 27 | try { |
| 28 | startDate = parseDateToLocal(task.scheduled); |
| 29 | } catch { |
| 30 | startDate = null; |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | if (!startDate || isNaN(startDate.getTime())) { |
| 35 | startDate = new Date(targetDate); |
| 36 | } |
| 37 | |
| 38 | if (isNaN(startDate.getTime())) { |
| 39 | startDate = new Date(); |
| 40 | } |
| 41 | |
| 42 | if (!task.scheduled || !hasTimeComponent(task.scheduled)) { |
| 43 | startDate.setHours(9, 0, 0, 0); |
| 44 | } |
| 45 | |
| 46 | const durationMinutes = task.timeEstimate && task.timeEstimate > 0 ? task.timeEstimate : 60; |
| 47 | const endDate = new Date(startDate.getTime() + durationMinutes * 60 * 1000); |
| 48 | |
| 49 | return { |
| 50 | date: formatDateForStorage(startDate), |
| 51 | startTime: formatTimeForInput(startDate), |
| 52 | endTime: formatTimeForInput(endDate), |
| 53 | }; |
| 54 | } |
no test coverage detected