/// <summary> /// Displays the calendar in the time zone identified by <paramref name="tzid"/>. /// </summary> static void ShowCalendar(iCalendar iCal, string tzid) { iCalDateTime start = new iCalDateTime(2007, 3, 1); iCalDateTime end = new iCalDateTime(2007, 4, 1).AddSeconds(-1); List<Occurrence> occurrences = iCal.GetOccurrences(start, end); Console.WriteLine("====Events/Todos/Journal Entries in " + tzid + "===="); foreach (Occurrence o in occurrences) { Console.WriteLine( o.Period.StartTime.ToTimeZone(tzid).ToString("ddd, MMM d - h:mm") + " to " + o.Period.EndTime.ToTimeZone(tzid).ToString("h:mm tt") + Environment.NewLine + o.Component.Summary + Environment.NewLine); } Console.WriteLine("====Alarms in " + tzid + "===="); foreach (RecurringComponent rc in iCal.RecurringComponents) { foreach (AlarmOccurrence ao in rc.PollAlarms(start, end)) { Console.WriteLine( "Alarm: " + ao.DateTime.ToTimeZone(tzid).ToString("ddd, MMM d - h:mm") + ": " + ao.Alarm.Summary); } } Console.WriteLine(); }
static void Main(string[] args) { // Create a new calendar IICalendar iCal = new iCalendar(); // Add the local time zone to the calendar ITimeZone local = iCal.AddLocalTimeZone(); // Build a list of additional time zones // from .NET Framework. List<ITimeZone> otherTimeZones = new List<ITimeZone>(); foreach (TimeZoneInfo tzi in System.TimeZoneInfo.GetSystemTimeZones()) { // We've already added the local time zone, so let's skip it! if (tzi != System.TimeZoneInfo.Local) { // Add the time zone to our list (but don't include it directly in the calendar). otherTimeZones.Add(iCalTimeZone.FromSystemTimeZone(tzi)); } } // Create a new event in the calendar // that uses our local time zone IEvent evt = iCal.Create<Event>(); evt.Summary = "Test Event"; evt.Start = iCalDateTime.Today.AddHours(8).SetTimeZone(local); evt.Duration = TimeSpan.FromHours(1); // Get all occurrences of the event that happen today foreach (Occurrence occurrence in iCal.GetOccurrences<IEvent>(iCalDateTime.Today)) { // Write the event with the time zone information attached Console.WriteLine(occurrence.Period.StartTime); // Note that the time printed is identical to the above, but without time zone information. Console.WriteLine(occurrence.Period.StartTime.Local); // Convert the start time to other time zones and display the relative time. foreach (ITimeZone otherTimeZone in otherTimeZones) Console.WriteLine(occurrence.Period.StartTime.ToTimeZone(otherTimeZone)); } }
private Calendar(string filePath) { _filePath = filePath; lock(fileLock) { _calendar = iCalendar.LoadFromStream(File.OpenRead(filePath)).FirstOrDefault() as iCalendar; _items = _calendar .GetOccurrences(new iCalDateTime(DateTime.Now), new iCalDateTime(DateTime.Now.AddYears(1))) .Select(o => new CalendarItem() { What = (o.Source as Event).Summary, Where = (o.Source as Event).Location, When = new iCalDateTime( o.Period.StartTime.Year, o.Period.StartTime.Month, o.Period.StartTime.Day, o.Period.StartTime.Hour, o.Period.StartTime.Minute, o.Period.StartTime.Second, "Europe/Amsterdam") // make sure that our timezone is correct }) .ToList(); } }