MCPcopy Create free account
hub / github.com/callumalpass/tasknotes / buildTimeblockPrefillForTask

Function buildTimeblockPrefillForTask

src/utils/timeblockPrefillUtils.ts:20–54  ·  view source on GitHub ↗
(
	task: TaskInfo,
	targetDate: Date
)

Source from the content-addressed store, hash-verified

18}
19
20export 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}

Callers 2

buildMenuMethod · 0.90

Calls 4

parseDateToLocalFunction · 0.90
hasTimeComponentFunction · 0.90
formatDateForStorageFunction · 0.90
formatTimeForInputFunction · 0.85

Tested by

no test coverage detected