how to find recurring events occurrences

145 Views Asked by At

I am using the Ical.net library in PowerShell, to read a Google Calendar .ics file and find the events it contains. For example I can get the date, time and summary of an event like this:

Add-Type -LiteralPath (Join-Path (Split-Path -Parent (Get-Package ICal.Net).Source) lib\netstandard2.0\Ical.Net.dll)
Add-Type -LiteralPath (Join-Path (Split-Path -Parent (Get-Package NodaTime).Source) lib\netstandard2.0\NodaTime.dll)

$ics = "$link_to/basic.ics"
$script:calendar = [Ical.Net.Calendar]::Load((Invoke-WebRequest $ics).Content)

foreach ($event in $calendar.Events) {
    Write-Host event date: ($event.DtStart.AsSystemLocal).ToString('dd/MM/yyyy')
    Write-Host event time: ($event.DtStart.AsSystemLocal).ToString('HH:mm')
    Write-Host event summary: $event.Summary
}

This code will output this:

event date: 28/04/2023                                                                                                  
event time: 20:00
event summary: doctor's appointment

The problem starts when I try to find the dates & times of recurring events. The exact same code will show me only the first occurrence of the event but none of the subsequent events.

If I run $calendar.RecurringItems I'll get this output:

DtStart            : 28/04/2023 8:00:00 PM Asia/Nicosia
DtEnd              : 28/04/2023 8:30:00 PM Asia/Nicosia
Duration           : 00:30:00
End                : 28/04/2023 8:30:00 PM Asia/Nicosia
IsAllDay           : False
GeographicLocation : 
Location           : 
Resources          : {}
Status             : CONFIRMED
Transparency       : OPAQUE
IsActive           : True
Attachments        : {}
Categories         : {}
Class              : 
Contacts           : {}
Created            : 01/05/2023 4:28:54 PM UTC
Description        : 
ExceptionDates     : {}
ExceptionRules     : {}
LastModified       : 01/05/2023 6:08:43 PM UTC
Priority           : 0
RecurrenceDates    : {}
RecurrenceRules    : {FREQ=DAILY}
RecurrenceId       : 
RelatedComponents  : {}
Sequence           : 1
Start              : 28/04/2023 8:00:00 PM Asia/Nicosia
Summary            : doctor's appointment
Alarms             : {}
Attendees          : {}
Comments           : {}
DtStamp            : 01/05/2023 6:13:44 PM UTC
Organizer          : 
RequestStatuses    : {}
Url                : 
Uid                : [email protected]
Properties         : {DTSTART, DTEND, RRULE, DTSTAMP…}
Parent             : Ical.Net.Calendar
Children           : {}
Name               : VEVENT
Calendar           : Ical.Net.Calendar
Line               : 0
Column             : 0
Group              : VEVENT
IsLoaded           : True

But RecurrenceDates is empty.

Even though in the Google Calendar I can see the event appears on a daily basis, the .ics file doesn't contain this information.

How can I find the subsequent events of a recurring event?

0

There are 0 best solutions below