ical.net library - show events in correct timezone

87 Views Asked by At

In PowerShell, I'm using the Ical.Net library to read a .ics file and extract the events, between a specific timeframe.

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)
$calendar = [Ical.Net.Calendar]::Load((Invoke-WebRequest $ics).Content)
$calendar.GetOccurrences('Saturday, May 13, 2023 1:00:00 AM', 'Saturday, May 13, 2023 2:00:00 AM').Source

In this example, I want to see the events occurring between 1AM and 2AM. The issue is that the library returns events occurring between 4AM and 5AM.

AssociatedObject : Ical.Net.CalendarComponents.CalendarEvent
AsSystemLocal    : 13/05/2023 4:00:00 AM
AsUtc            : 13/05/2023 1:00:00 AM
Value            : 13/05/2023 1:00:00 AM
IsUtc            : True
HasDate          : True
HasTime          : True
TzId             : UTC
TimeZoneName     : UTC
Year             : 2023
Month            : 5
Day              : 13
Hour             : 1
Minute           : 0
Second           : 0
Millisecond      : 0
Ticks            : 638195364000000000
DayOfWeek        : Saturday
DayOfYear        : 133
Date             : 13/05/2023 12:00:00 AM
TimeOfDay        : 01:00:00
AsDateTimeOffset : 13/05/2023 1:00:00 AM +00:00
Encoding         : 
Calendar         : Ical.Net.Calendar
Language         : 
Parameters       : {TZID}

AssociatedObject : Ical.Net.CalendarComponents.CalendarEvent
AsSystemLocal    : 13/05/2023 5:00:00 AM
AsUtc            : 13/05/2023 2:00:00 AM
Value            : 13/05/2023 2:00:00 AM
IsUtc            : True
HasDate          : True
HasTime          : True
TzId             : UTC
TimeZoneName     : UTC
Year             : 2023
Month            : 5
Day              : 13
Hour             : 2
Minute           : 0
Second           : 0
Millisecond      : 0
Ticks            : 638195400000000000
DayOfWeek        : Saturday
DayOfYear        : 133
Date             : 13/05/2023 12:00:00 AM
TimeOfDay        : 02:00:00
AsDateTimeOffset : 13/05/2023 2:00:00 AM +00:00
Encoding         : 
Calendar         : Ical.Net.Calendar
Language         : 
Parameters       : {TZID}

This has to be a time zone issue, as I'm located at GTM+3

How do I modify this command to view events between 1AM and 2AM?

0

There are 0 best solutions below