Fix data loss risk, reminder bugs; theme, credits, tests
- Store tasks in %APPDATA% (single-file extract dir lost data on update), atomic serialized saves, corrupt-file backup, migration of old tasks.json - Reminders without description never showed (empty balloon text threw) - Catch up missed reminders on start; monthly recurrence no longer drifts - Task dialog: date pick kept 00:00, cancel leaked recurrence changes - CSV import understands quoted fields written by export - Confirm before deleting; name folders on create; tasks sorted by date - Single instance, autostart starts hidden in tray, tray icon disposed - Theme helper for all dialogs, MDL2/Path icons instead of emojis, fixed folder selection/badge, localized counts and messages - Credits (c) Michael Media + Discord link, exe Company/Copyright - Locales embedded; xUnit tests (24); README, CLAUDE.md, sprite-generator Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -57,23 +57,63 @@ namespace ReminderOrganizer.Models
|
||||
set => SetProperty(ref _recurrenceType, value);
|
||||
}
|
||||
|
||||
public DateTime GetNextOccurrence()
|
||||
public DateTime GetNextOccurrence() => GetNextOccurrence(DateTime.Now);
|
||||
|
||||
/// <summary>
|
||||
/// First occurrence after <paramref name="now"/>. Steps are counted from the original
|
||||
/// date, so "31 Jan monthly" gives 29 Feb, 31 Mar, 30 Apr … instead of drifting to the 28th.
|
||||
/// </summary>
|
||||
public DateTime GetNextOccurrence(DateTime now)
|
||||
{
|
||||
var next = ReminderDate;
|
||||
while (next <= DateTime.Now)
|
||||
var start = ReminderDate;
|
||||
if (start > now) return start;
|
||||
|
||||
// Jump close to "now" first so long gaps (app off for years) don't loop thousands of times.
|
||||
int k = RecurrenceType switch
|
||||
{
|
||||
RecurrenceType.Daily => Math.Max(0, (int)((now - start).TotalDays) - 1),
|
||||
RecurrenceType.Weekly => Math.Max(0, (int)((now - start).TotalDays / 7) - 1),
|
||||
RecurrenceType.Monthly => Math.Max(0, (now.Year - start.Year) * 12 + now.Month - start.Month - 1),
|
||||
_ => Math.Max(0, now.Year - start.Year - 1)
|
||||
};
|
||||
|
||||
DateTime next;
|
||||
do
|
||||
{
|
||||
k++;
|
||||
next = RecurrenceType switch
|
||||
{
|
||||
RecurrenceType.Daily => next.AddDays(1),
|
||||
RecurrenceType.Weekly => next.AddDays(7),
|
||||
RecurrenceType.Monthly => next.AddMonths(1),
|
||||
RecurrenceType.Yearly => next.AddYears(1),
|
||||
_ => next.AddYears(1)
|
||||
RecurrenceType.Daily => start.AddDays(k),
|
||||
RecurrenceType.Weekly => start.AddDays(7 * k),
|
||||
RecurrenceType.Monthly => start.AddMonths(k),
|
||||
_ => start.AddYears(k)
|
||||
};
|
||||
}
|
||||
} while (next <= now);
|
||||
return next;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Marks every due task: one-off tasks become notified, recurring ones move to their next date.
|
||||
/// Returns the tasks that should be shown as a notification now.
|
||||
/// </summary>
|
||||
public static System.Collections.Generic.List<ReminderTask> ProcessDue(System.Collections.Generic.IEnumerable<Folder> folders, DateTime now)
|
||||
{
|
||||
var due = new System.Collections.Generic.List<ReminderTask>();
|
||||
foreach (var folder in folders)
|
||||
{
|
||||
foreach (var task in folder.Tasks)
|
||||
{
|
||||
if (task.IsNotified || task.ReminderDate > now) continue;
|
||||
due.Add(task);
|
||||
if (task.IsRecurring)
|
||||
task.ReminderDate = task.GetNextOccurrence(now);
|
||||
else
|
||||
task.IsNotified = true;
|
||||
}
|
||||
}
|
||||
return due;
|
||||
}
|
||||
|
||||
public ReminderTask() { }
|
||||
|
||||
public ReminderTask(string name, string description, DateTime reminderDate)
|
||||
|
||||
Reference in New Issue
Block a user