Exemple #1
0
        public void GOOGLE1()
        {
            TZID      tzid = "Europe/Berlin";
            iCalendar iCal = iCalendar.LoadFromFile(@"Calendars/General/GoogleCalendar.ics");
            Event     evt  = iCal.Events["*****@*****.**"];

            Assert.IsNotNull(evt);

            Date_Time dtStart = new Date_Time(2006, 12, 18, tzid, iCal);
            Date_Time dtEnd   = new Date_Time(2006, 12, 23, tzid, iCal);

            iCal.Evaluate(dtStart, dtEnd);

            Date_Time[] DateTimes = new Date_Time[]
            {
                new Date_Time(2006, 12, 11, 7, 0, 0, tzid, iCal),
                new Date_Time(2006, 12, 18, 7, 0, 0, tzid, iCal),
                new Date_Time(2006, 12, 19, 7, 0, 0, tzid, iCal),
                new Date_Time(2006, 12, 20, 7, 0, 0, tzid, iCal),
                new Date_Time(2006, 12, 21, 7, 0, 0, tzid, iCal),
                new Date_Time(2006, 12, 22, 7, 0, 0, tzid, iCal)
            };

            foreach (Date_Time dt in DateTimes)
            {
                Assert.IsTrue(evt.OccursAt(dt), "Event should occur at " + dt);
            }

            Assert.IsTrue(evt.Periods.Count == DateTimes.Length, "There should be exactly " + DateTimes.Length + " occurrences; there were " + evt.Periods.Count);
        }
Exemple #2
0
        public void LoadAndDisplayCalendar()
        {
            // The following code loads and displays an iCalendar
            // with US Holidays for 2006.
            //
            iCalendar iCal = iCalendar.LoadFromFile(@"Calendars\General\USHolidays.ics");

            Assert.IsNotNull(iCal, "iCalendar did not load.  Are you connected to the internet?");
            iCal.Evaluate(
                new Date_Time(2006, 1, 1, "US-Eastern", iCal),
                new Date_Time(2006, 12, 31, "US-Eastern", iCal));

            Date_Time dt = new Date_Time(2006, 1, 1, "US-Eastern", iCal);

            while (dt.Year == 2006)
            {
                // First, display the current date we're evaluating
                Console.WriteLine(dt.Local.ToShortDateString());

                // Then, iterate through each event in our iCalendar
                foreach (Event evt in iCal.Events)
                {
                    // Determine if the event occurs on the specified date
                    if (evt.OccursOn(dt))
                    {
                        // Display the event summary
                        Console.Write("\t" + evt.Summary);

                        // Display the time the event happens (unless it's an all-day event)
                        if (evt.Start.HasTime)
                        {
                            Console.Write(" (" + evt.Start.Local.ToShortTimeString() + " - " + evt.End.Local.ToShortTimeString());
                            if (evt.Start.TimeZoneInfo != null)
                            {
                                Console.Write(" " + evt.Start.TimeZoneInfo.TimeZoneName);
                            }
                            Console.Write(")");
                        }

                        Console.Write(Environment.NewLine);
                    }
                }

                // Move to the next day
                dt = dt.AddDays(1);
            }
        }