#nullable enable using System; using System.Collections.Generic; using System.Linq; using ReminderOrganizer.Models; namespace ReminderOrganizer.Core { /// Content of the morning summary. Null when there is nothing worth showing. public sealed record DailySummaryData( IReadOnlyList Today, IReadOnlyList Overdue, IReadOnlyList AnniversariesSoon); public static class DailySummary { /// Days ahead in which anniversaries are announced (tomorrow … in 3 days). public const int AnniversaryDays = 3; public static DailySummaryData? Build(IEnumerable tasks, DateTime now) { var open = tasks.Where(t => !t.IsNotified).ToList(); var today = open.Where(t => t.ReminderDate.Date == now.Date).OrderBy(t => t.ReminderDate).ToList(); var overdue = open.Where(t => !t.IsRecurring && t.ReminderDate.Date < now.Date).OrderBy(t => t.ReminderDate).ToList(); var soon = open.Where(t => t.IsAnniversary) .Where(t => (t.ReminderDate.Date - now.Date).Days is > 0 and <= AnniversaryDays) .OrderBy(t => t.ReminderDate).ToList(); return today.Count + overdue.Count + soon.Count == 0 ? null : new DailySummaryData(today, overdue, soon); } /// Should the summary be shown now? Once per day, from on. public static bool IsDue(DateTime now, int hour, DateTime? lastShown) => now.Hour >= hour && (lastShown == null || lastShown.Value.Date < now.Date); } }