I am migrating my application from dday.ical to ical.net and am struggling with TimeZones.
I managed to rewrite adding the TimeZone from
IICalendarCollection calendarCollection = iCalendar.LoadFromUri(new Uri(GoogleCalendarUrl));
IICalendar calendar = calendarCollection.FirstOrDefault();
string timeZone = "<some timezone>";
if (!string.IsNullOrWhiteSpace(timeZone))
{
System.TimeZoneInfo timezoneinfo = System.TimeZoneInfo.FindSystemTimeZoneById(timeZone);
calendar.AddTimeZone(timezoneinfo);
}
to the ical.net equivalent
IICalendarCollection calendarCollection = LoadFromUri(new Uri(GoogleCalendarUrl));
ICalendar calendar = calendarCollection.FirstOrDefault();
string timeZone = "<some timezone>";
if (!string.IsNullOrWhiteSpace(timeZone))
{
((Calendar)calendar).AddTimeZone(new VTimeZone(timeZone));
}
But I have no clue on how to use the TimeZone in ical.net
My dday.ical code for using the TimeZone is
iCalTimeZone timezone = null;
if (!string.IsNullOrWhiteSpace(TimeZone))
{
System.TimeZoneInfo timezoneinfo = System.TimeZoneInfo.FindSystemTimeZoneById(TimeZone);
timezone = iCalTimeZone.FromSystemTimeZone(timezoneinfo);
}
Occurrence occurrence = <filled from other code part>;
IEvent iEvent = occurrence.Source as IEvent;
IPeriod period = occurrence.Period;
if ((iEvent != null) && (period != null))
{
if (!string.IsNullOrWhiteSpace(TimeZone))
{
period.StartTime.SetTimeZone(timezone);
period.EndTime.SetTimeZone(timezone);
}
DateTime localStartTime = period.StartTime.Local;
DateTime localEndTime = period.EndTime.Local;
// Do something with local start and end time.
// ...
}
The purpose of my code is to read a private Google Calendar which contains Scheduled events for heating my house (at 19:00 it should be 19 degrees celcius etc) and to use these events to control a heating device.
The events in the Google Calendar have the TimeZone '(GMT+01:00) Amsterdam'.
In the DDay.Cal code the Local property of the StartTime and EndTime for an IEvent were one hour off because of the Amsterdam TimeZone. The code as written above fixed this by setting the TimeZone of the StartTime and EndTime properties of IEvent. This corrected the time, in this case for one hour.
Can anyone please help me on how to (re)write the mentioned use of the TimeZone to the ical.net equivalent?