@@ -2,11 +2,7 @@ import moment, { type Moment } from "moment";
22import { tz } from "moment-timezone" ;
33import ical , { type AttendeePartStat } from "node-ical" ;
44
5- import {
6- fallbackPartStat ,
7- noTitle ,
8- originalRecurrenceDayKeyFormat ,
9- } from "../constants" ;
5+ import { fallbackPartStat , noTitle , icalDayKeyFormat } from "../constants" ;
106import type { RemoteTask , WithTime } from "../task-types" ;
117import type { WithIcalConfig } from "../types" ;
128
@@ -25,14 +21,24 @@ export function canHappenAfter(icalEvent: ical.VEvent, date: Date) {
2521 ) ;
2622}
2723
28- function hasRecurrenceOverride ( icalEvent : ical . VEvent , date : Date ) {
24+ function hasRecurrenceOverrideForDate ( icalEvent : ical . VEvent , date : Date ) {
2925 if ( ! icalEvent . recurrences ) {
3026 return false ;
3127 }
3228
33- const dateKey = moment ( date ) . format ( originalRecurrenceDayKeyFormat ) ;
29+ return Object . hasOwn ( icalEvent . recurrences , getIcalDayKey ( date ) ) ;
30+ }
31+
32+ function getIcalDayKey ( date : Date ) {
33+ return moment ( date ) . format ( icalDayKeyFormat ) ;
34+ }
35+
36+ function hasExceptionForDate ( icalEvent : ical . VEvent , date : Date ) {
37+ if ( ! icalEvent . exdate ) {
38+ return false ;
39+ }
3440
35- return Object . hasOwn ( icalEvent . recurrences , dateKey ) ;
41+ return Object . keys ( icalEvent . exdate ) . includes ( getIcalDayKey ( date ) ) ;
3642}
3743
3844export function icalEventToTasks (
@@ -53,7 +59,11 @@ export function icalEventToTasks(
5359
5460 const recurrences = icalEvent . rrule
5561 ?. between ( startOfDay , endOfDay )
56- . filter ( ( date ) => ! hasRecurrenceOverride ( icalEvent , date ) )
62+ . filter (
63+ ( date ) =>
64+ ! hasRecurrenceOverrideForDate ( icalEvent , date ) &&
65+ ! hasExceptionForDate ( icalEvent , date ) ,
66+ )
5767 . map ( ( date ) => icalEventToTask ( icalEvent , date ) ) ;
5868
5969 return [ ...recurrences , ...recurrenceOverrides ] ;
0 commit comments