Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 40 additions & 32 deletions src/services/CalendarExportService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,19 @@ export class CalendarExportService {
params.append("subject", task.title);

// Handle dates
const { startISO, endISO } = this.getTaskDateRange(task, useScheduledAsDue);
if (startISO) {
params.append("startdt", startISO);
const { allDay, start, end } = this.getLinkDates(task, useScheduledAsDue);
const toOutlook = (value: string) =>
allDay
? `${value.slice(0, 4)}-${value.slice(4, 6)}-${value.slice(6, 8)}`
: this.parseICSDate(value).toISOString();
if (start) {
params.append("startdt", toOutlook(start));
}
if (endISO) {
params.append("enddt", endISO);
if (end) {
params.append("enddt", toOutlook(end));
}
if (allDay) {
params.append("allday", "true");
}

// Add description
Expand Down Expand Up @@ -134,13 +141,17 @@ export class CalendarExportService {
params.append("v", "60"); // Required parameter
params.append("title", task.title);

// Handle dates (Yahoo uses YYYYMMDDTHHmmss format)
const { startYahoo, endYahoo } = this.getYahooDateFormat(task, useScheduledAsDue);
if (startYahoo) {
params.append("st", startYahoo);
// Handle dates (Yahoo uses YYYYMMDDTHHmmss format, or YYYYMMDD with dur=allday)
const { allDay, start, end } = this.getLinkDates(task, useScheduledAsDue);
const toYahoo = (value: string) =>
allDay ? value : format(this.parseICSDate(value), "yyyyMMdd'T'HHmmss");
if (start) {
params.append("st", toYahoo(start));
}
if (endYahoo) {
params.append("et", endYahoo);
if (allDay) {
params.append("dur", "allday");
} else if (end) {
params.append("et", toYahoo(end));
}

// Add description
Expand Down Expand Up @@ -302,7 +313,7 @@ export class CalendarExportService {
* Format dates for Google Calendar (YYYYMMDDTHHmmssZ/YYYYMMDDTHHmmssZ)
*/
private static formatGoogleDates(task: TaskInfo, useScheduledAsDue: boolean): string | null {
const { startICS, endICS } = this.getICSDateFormat(task, useScheduledAsDue);
const { start: startICS, end: endICS } = this.getLinkDates(task, useScheduledAsDue);

if (!startICS) return null;

Expand All @@ -319,6 +330,23 @@ export class CalendarExportService {
return `${startICS}/${endFormatted}`;
}

/**
* Event dates for the calendar links, from the same rules as the ICS export:
* all-day values are YYYYMMDD (end exclusive), timed values YYYYMMDDTHHMMSSZ.
*/
private static getLinkDates(
task: TaskInfo,
useScheduledAsDue: boolean
): { allDay: boolean; start: string | null; end: string | null } {
const { startLine, endLine } = this.getICSDateProperties(task, useScheduledAsDue);
const value = (line: string | null) => (line ? line.slice(line.indexOf(":") + 1) : null);
return {
allDay: startLine?.includes("VALUE=DATE") ?? false,
start: value(startLine),
end: value(endLine),
};
}

/**
* Get task date range in ISO format
*/
Expand Down Expand Up @@ -376,26 +404,6 @@ export class CalendarExportService {
return { startISO, endISO };
}

/**
* Format dates for Yahoo Calendar (YYYYMMDDTHHMMSS)
*/
private static getYahooDateFormat(
task: TaskInfo,
useScheduledAsDue: boolean
): { startYahoo: string | null; endYahoo: string | null } {
const { startISO, endISO } = this.getTaskDateRange(task, useScheduledAsDue);

const formatYahoo = (isoString: string): string => {
const date = new Date(isoString);
return format(date, "yyyyMMdd'T'HHmmss");
};

return {
startYahoo: startISO ? formatYahoo(startISO) : null,
endYahoo: endISO ? formatYahoo(endISO) : null,
};
}

/**
* Format dates for ICS format (YYYYMMDDTHHMMSSZ)
*/
Expand Down
27 changes: 27 additions & 0 deletions tests/unit/services/calendar-export-due-only.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,30 @@ describe("ICS export of tasks with only a due date", () => {
expect(ics).not.toContain("DTSTART:20261102");
});
});

describe("calendar links for tasks with only a due date", () => {
const link = (type: "google" | "outlook" | "yahoo", due: string) =>
new URL(CalendarExportService.generateCalendarURL({ type, task: dueOnly(due) }))
.searchParams;

it("puts a date-only due on that day as an all-day event", () => {
expect(link("google", "2026-11-20").get("dates")).toBe("20261120/20261121");
const outlook = link("outlook", "2026-11-20");
expect([outlook.get("startdt"), outlook.get("enddt"), outlook.get("allday")]).toEqual([
"2026-11-20",
"2026-11-21",
"true",
]);
const yahoo = link("yahoo", "2026-11-20");
expect([yahoo.get("st"), yahoo.get("dur")]).toEqual(["20261120", "allday"]);
});

it("starts a timed due at the due time", () => {
expect(link("google", "2026-11-20T14:30:00Z").get("dates")).toBe(
"20261120T143000Z/20261120T153000Z"
);
const outlook = link("outlook", "2026-11-20T14:30:00Z");
expect(outlook.get("startdt")).toBe("2026-11-20T14:30:00.000Z");
expect(outlook.get("enddt")).toBe("2026-11-20T15:30:00.000Z");
});
});
Loading