Skip to content

Fix end-time reminder firing at event start instead of end (ical.net Period.EndTime null bug)#17

Merged
wen-templari merged 2 commits intomainfrom
copilot/fix-schedule-reminder-end-time-parsing
Mar 27, 2026
Merged

Fix end-time reminder firing at event start instead of end (ical.net Period.EndTime null bug)#17
wen-templari merged 2 commits intomainfrom
copilot/fix-schedule-reminder-end-time-parsing

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 27, 2026

occurrence.Period.EndTime is always null in ical.net 5.1.1 when using the single-argument GetOccurrences(startArg) overload. The Period wrapper silently fell back to StartTime, so end reminders were scheduled 5 min before the event start rather than its end — and the displayed end time was wrong.

Confirmed against the live calendar: for NWDC(BaaS)with DTSTART=20:30 DTEND=22:30, the end reminder fired at 20:25 instead of 22:25.

Changes

  • CalendarExtensions.csPeriod.EndTime: Replace the p.EndTime ?? p.StartTime fallback with a ComputeEndTime() helper that derives end time as occurrence.Start + (ev.End − ev.Start). Using duration rather than ev.End directly is required for recurring events — ev.End carries the base occurrence's date and would be wrong for all future recurrences.

    // Before: silent wrong fallback
    public DateTimeOffset EndTime { get; } = (p.EndTime ?? p.StartTime).ToLocalNetworkTime();
    
    // After: duration-based, correct for both single and recurring events
    private static DateTimeOffset ComputeEndTime(Period p, CalendarEvent? calendarEvent)
    {
        if (p.EndTime is not null) return p.EndTime.ToLocalNetworkTime();
        if (calendarEvent?.Start is not null)
        {
            var duration = (calendarEvent.End?.AsUtc ?? calendarEvent.Start.AsUtc)
                         - calendarEvent.Start.AsUtc;
            var endUtc = p.StartTime.AsUtc.Add(duration);
            return new DateTimeOffset(endUtc).ToOffset(NetworkTime.LocalTimeZoneOffset);
        }
        return p.StartTime.ToLocalNetworkTime();
    }
  • CalendarExtensions.csGetEvents(): Pass calendarEvent to the Period constructor so it has access to the event duration.

  • ReminderTask.cs: End reminder message and log now display eventEndTime (the per-occurrence computed value) instead of ev.End?.ToLocalNetworkTime(). Also fixes the log text "分钟后开始日程" → "分钟后结束日程".


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…nt when Period.EndTime is null (ical.net 5.1.1 bug)

Agent-Logs-Url: https://github.com/nbtca/HuaJiBot.NET/sessions/98314277-209b-4b98-8be4-d16c908c5ad5

Co-authored-by: wen-templari <52404670+wen-templari@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix parsing issue with schedule reminder end time Fix end-time reminder firing at event start instead of end (ical.net Period.EndTime null bug) Mar 27, 2026
Copilot AI requested a review from wen-templari March 27, 2026 12:59
@wen-templari wen-templari marked this pull request as ready for review March 27, 2026 14:02
@wen-templari wen-templari merged commit cb89eda into main Mar 27, 2026
5 checks passed
@wen-templari wen-templari deleted the copilot/fix-schedule-reminder-end-time-parsing branch March 27, 2026 14:03
@wen-templari wen-templari linked an issue Mar 27, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

日程提醒结束时间的解析似乎有问题

2 participants