Upcoming view, search/filters, lead reminders, birthdays, folder colors, ICS, sound, undo
- Upcoming: all folders grouped by overdue/today/tomorrow/7 days/later/done
- Search (Ctrl+F) + All/Today/Overdue filters + hide done (persisted)
- Lead reminder 1/2/3 days or 1 week before; birth year shows age
- Several due reminders are combined into one balloon
- Folder colors and reordering (drag, context menu)
- iCalendar export with RRULE and VALARM
- Generated reminder chime (ComfyUI / Stable Audio), can be turned off
- Undo snackbar for deleted tasks/folders (Ctrl+Z), Ctrl+N, Del, Esc
- 41 tests
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 15:03:36 +01:00
|
|
|
#nullable enable
|
|
|
|
|
using System;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using ReminderOrganizer.Models;
|
|
|
|
|
|
|
|
|
|
namespace ReminderOrganizer.Services
|
|
|
|
|
{
|
|
|
|
|
/// <summary>iCalendar (.ics) export for Outlook, Google Calendar, Apple Calendar.</summary>
|
|
|
|
|
public static class IcsExport
|
|
|
|
|
{
|
|
|
|
|
public static string Build(AppData data, DateTime utcNow)
|
|
|
|
|
{
|
|
|
|
|
var sb = new StringBuilder();
|
|
|
|
|
void Line(string s) => sb.Append(Fold(s)).Append("\r\n");
|
|
|
|
|
|
|
|
|
|
Line("BEGIN:VCALENDAR");
|
|
|
|
|
Line("VERSION:2.0");
|
|
|
|
|
Line("PRODID:-//Michael Media//Reminder Organizer//EN");
|
|
|
|
|
Line("CALSCALE:GREGORIAN");
|
|
|
|
|
var stamp = utcNow.ToUniversalTime().ToString("yyyyMMdd'T'HHmmss'Z'", CultureInfo.InvariantCulture);
|
|
|
|
|
|
|
|
|
|
foreach (var folder in data.Folders)
|
|
|
|
|
{
|
|
|
|
|
foreach (var t in folder.Tasks)
|
|
|
|
|
{
|
|
|
|
|
if (t.IsNotified) continue;
|
|
|
|
|
Line("BEGIN:VEVENT");
|
|
|
|
|
Line($"UID:{t.Id}@reminder-organizer");
|
|
|
|
|
Line($"DTSTAMP:{stamp}");
|
2026-11-29 14:42:16 +01:00
|
|
|
if (t.IsBirthday)
|
|
|
|
|
{
|
|
|
|
|
// all-day event
|
|
|
|
|
Line($"DTSTART;VALUE=DATE:{t.ReminderDate.ToString("yyyyMMdd", CultureInfo.InvariantCulture)}");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// floating local time: shows at the same clock time in every calendar
|
|
|
|
|
Line($"DTSTART:{t.ReminderDate.ToString("yyyyMMdd'T'HHmmss", CultureInfo.InvariantCulture)}");
|
|
|
|
|
Line("DURATION:PT30M");
|
|
|
|
|
}
|
Upcoming view, search/filters, lead reminders, birthdays, folder colors, ICS, sound, undo
- Upcoming: all folders grouped by overdue/today/tomorrow/7 days/later/done
- Search (Ctrl+F) + All/Today/Overdue filters + hide done (persisted)
- Lead reminder 1/2/3 days or 1 week before; birth year shows age
- Several due reminders are combined into one balloon
- Folder colors and reordering (drag, context menu)
- iCalendar export with RRULE and VALARM
- Generated reminder chime (ComfyUI / Stable Audio), can be turned off
- Undo snackbar for deleted tasks/folders (Ctrl+Z), Ctrl+N, Del, Esc
- 41 tests
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 15:03:36 +01:00
|
|
|
var summary = t.UpcomingAge is int age ? $"{t.Name} ({age})" : t.Name;
|
|
|
|
|
Line($"SUMMARY:{Escape(summary)}");
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(t.Description)) Line($"DESCRIPTION:{Escape(t.Description)}");
|
|
|
|
|
Line($"CATEGORIES:{Escape(folder.Name)}");
|
|
|
|
|
if (t.IsRecurring)
|
|
|
|
|
{
|
|
|
|
|
var freq = t.RecurrenceType switch
|
|
|
|
|
{
|
|
|
|
|
RecurrenceType.Daily => "DAILY",
|
|
|
|
|
RecurrenceType.Weekly => "WEEKLY",
|
|
|
|
|
RecurrenceType.Monthly => "MONTHLY",
|
|
|
|
|
_ => "YEARLY"
|
|
|
|
|
};
|
|
|
|
|
Line($"RRULE:FREQ={freq}");
|
|
|
|
|
}
|
|
|
|
|
Line("BEGIN:VALARM");
|
|
|
|
|
Line("ACTION:DISPLAY");
|
|
|
|
|
Line($"DESCRIPTION:{Escape(t.Name)}");
|
2026-11-29 14:42:16 +01:00
|
|
|
// all-day events start at midnight: remind at 09:00 (same day or lead days before)
|
|
|
|
|
Line(t.IsBirthday
|
|
|
|
|
? (t.LeadDays > 0 ? $"TRIGGER:-P{t.LeadDays - 1}DT15H" : "TRIGGER:PT9H")
|
|
|
|
|
: (t.LeadDays > 0 ? $"TRIGGER:-P{t.LeadDays}D" : "TRIGGER:PT0M"));
|
Upcoming view, search/filters, lead reminders, birthdays, folder colors, ICS, sound, undo
- Upcoming: all folders grouped by overdue/today/tomorrow/7 days/later/done
- Search (Ctrl+F) + All/Today/Overdue filters + hide done (persisted)
- Lead reminder 1/2/3 days or 1 week before; birth year shows age
- Several due reminders are combined into one balloon
- Folder colors and reordering (drag, context menu)
- iCalendar export with RRULE and VALARM
- Generated reminder chime (ComfyUI / Stable Audio), can be turned off
- Undo snackbar for deleted tasks/folders (Ctrl+Z), Ctrl+N, Del, Esc
- 41 tests
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 15:03:36 +01:00
|
|
|
Line("END:VALARM");
|
|
|
|
|
Line("END:VEVENT");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Line("END:VCALENDAR");
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string Escape(string s) =>
|
|
|
|
|
s.Replace("\\", "\\\\").Replace(";", "\\;").Replace(",", "\\,").Replace("\r\n", "\\n").Replace("\n", "\\n").Replace("\r", "");
|
|
|
|
|
|
|
|
|
|
/// <summary>RFC 5545: lines longer than 75 octets continue with CRLF + space.</summary>
|
|
|
|
|
public static string Fold(string line)
|
|
|
|
|
{
|
|
|
|
|
var bytes = Encoding.UTF8.GetByteCount(line);
|
|
|
|
|
if (bytes <= 75) return line;
|
|
|
|
|
var sb = new StringBuilder();
|
|
|
|
|
int count = 0;
|
|
|
|
|
foreach (var ch in line)
|
|
|
|
|
{
|
|
|
|
|
int n = Encoding.UTF8.GetByteCount(ch.ToString());
|
|
|
|
|
if (count + n > 75) { sb.Append("\r\n "); count = 1; }
|
|
|
|
|
sb.Append(ch);
|
|
|
|
|
count += n;
|
|
|
|
|
}
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|