MCPcopy
hub / github.com/callumalpass/tasknotes / computeDueFromICSEnd

Method computeDueFromICSEnd

src/services/ICSNoteService.ts:323–355  ·  view source on GitHub ↗

* Convert ICSEvent.end to a safe due date string * - All-day events: Use the start date (ICS all-day events have DTEND as the next day per spec) * - Timed events: Use the actual end time * - No end time: Return undefined

(icsEvent: ICSEvent)

Source from the content-addressed store, hash-verified

321 * - No end time: Return undefined
322 */
323 private computeDueFromICSEnd(icsEvent: ICSEvent): string | undefined {
324 try {
325 // No end time means no due date
326 if (!icsEvent.end) return undefined;
327
328 // For all-day events, the ICS spec uses DTEND as the day AFTER the event
329 // e.g., an all-day event on Feb 12 has DTSTART=20250212 and DTEND=20250213
330 // So we use the start date as the due date for all-day events
331 if (icsEvent.allDay) {
332 if (!icsEvent.start) return undefined;
333 const startDateStr = /^\d{4}-\d{2}-\d{2}$/.test(icsEvent.start)
334 ? icsEvent.start + "T00:00:00"
335 : icsEvent.start;
336 const startDate = new Date(startDateStr);
337 return formatDateForStorage(startDate);
338 }
339
340 // Timed event: use the actual end time
341 const endDateStr = /^\d{4}-\d{2}-\d{2}$/.test(icsEvent.end)
342 ? icsEvent.end + "T00:00:00"
343 : icsEvent.end;
344 const endDate = new Date(endDateStr);
345 return format(endDate, "yyyy-MM-dd'T'HH:mm");
346 } catch (error) {
347 tasknotesLogger.warn("Failed to compute due from ICS event end:", {
348 category: "provider",
349 operation: "compute-due-ics-event-end",
350 details: { end: icsEvent.end },
351 error: error,
352 });
353 return undefined;
354 }
355 }
356
357 /**
358 * Create a new note from an ICS event

Callers 1

createTaskFromICSMethod · 0.95

Calls 2

formatDateForStorageFunction · 0.90
warnMethod · 0.80

Tested by

no test coverage detected