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>
This commit is contained in:
81
Services/IcsExport.cs
Normal file
81
Services/IcsExport.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
#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}");
|
||||
// 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");
|
||||
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)}");
|
||||
Line(t.LeadDays > 0 ? $"TRIGGER:-P{t.LeadDays}D" : "TRIGGER:PT0M");
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user