I am trying to get occurrences out of a homemade iCal, but in some cases, it seems that the first two occurrences have an incorrect UTC property, and I believe this is because they have a null TimeZoneObservance, despite the iCal being properly set with a time zone. Here's the code:
static void Main(string[] args) { IICalendar iCal = new iCalendar(); iCal.AddTimeZone(TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time")); string tzid = iCal.TimeZones[0].TZID; // Need this when we make iCal date/time objects IEvent Evt = iCal.Create<Event>(); Evt.Summary = "Test"; // This is just a dummy name Evt.Start = new iCalDateTime(new DateTime(2012, 9, 28, 12, 00, 00, DateTimeKind.Unspecified), tzid); Evt.End = Evt.Start.AddMinutes(30); Evt.Start.AssociatedObject = Evt.End.AssociatedObject = iCal; Debug.Print("Evt.Start={0}, Evt.Start.UTC={1}", Evt.Start, Evt.Start.UTC); var iCalFrom = new iCalDateTime(new DateTime(2012, 9, 28, 12, 00, 00, DateTimeKind.Unspecified), tzid); var iCalTo = new iCalDateTime(new DateTime(2013, 8, 28, 12, 00, 00, DateTimeKind.Unspecified), tzid); iCalTo.AssociatedObject = iCalFrom.AssociatedObject = iCal; Evt.RecurrenceRules.Add(new RecurrencePattern("FREQ=MONTHLY;INTERVAL=1;BYMONTHDAY=28;WKST=SU;COUNT=10;")); IList<Occurrence> Occurrences = Evt.GetOccurrences(iCalFrom, iCalTo); foreach (var o in Occurrences) Debug.Print("{0} (UTC={1})", o.Period.StartTime, o.Period.StartTime.UTC); }
Here's the Debug.Print output:
9/28/2012 12:00:00 PM (UTC=09/28/2012 16:00:00) 10/28/2012 12:00:00 PM (UTC=10/28/2012 16:00:00) 11/28/2012 12:00:00 PM Pacific Standard Time (UTC=11/28/2012 20:00:00) 12/28/2012 12:00:00 PM Pacific Standard Time (UTC=12/28/2012 20:00:00) 1/28/2013 12:00:00 PM Pacific Standard Time (UTC=01/28/2013 20:00:00) 2/28/2013 12:00:00 PM Pacific Standard Time (UTC=02/28/2013 20:00:00) 3/28/2013 12:00:00 PM Pacific Daylight Time (UTC=03/28/2013 19:00:00) 4/28/2013 12:00:00 PM Pacific Daylight Time (UTC=04/28/2013 19:00:00) 5/28/2013 12:00:00 PM Pacific Daylight Time (UTC=05/28/2013 19:00:00) 6/28/2013 12:00:00 PM Pacific Daylight Time (UTC=06/28/2013 19:00:00)
Notice that the first two don't show a TZ from the ToString(), and while the local time is correct, the UTC is not. I believe that this happens for the occurrences before the first DST to STD time transition. This also only is a problem when I use a time zone other than the local time zone and a time zone that has DST. Thus if I use "Eastern Time Zone" (where I am) or "US Mountain Time Zone" (for Arizona, which does not use DST), I don't see this problem.