Exemplo n.º 1
0
        public void RRULE43()
        {
            iCalendar iCal = new iCalendar();

            iCalTimeZone tz = iCal.Create<iCalTimeZone>();
            
            tz.TZID = "US-Eastern";
            tz.Last_Modified = new DateTime(1987, 1, 1, 0, 0, 0, DateTimeKind.Utc);

            TimeZoneInfo standard = new TimeZoneInfo(iCalTimeZone.STANDARD, tz);
            standard.Start = new DateTime(1967, 10, 29, 2, 0, 0, DateTimeKind.Utc);            
            standard.AddRecurrencePattern(new RecurrencePattern("FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10"));
            standard.TZOffsetFrom = new UTC_Offset("-0400");
            standard.TZOffsetTo = new UTC_Offset("-0500");
            standard.TimeZoneName = "EST";            

            TimeZoneInfo daylight = new TimeZoneInfo(iCalTimeZone.DAYLIGHT, tz);
            daylight.Start = new DateTime(1987, 4, 5, 2, 0, 0, DateTimeKind.Utc);
            daylight.AddRecurrencePattern(new RecurrencePattern("FREQ=YEARLY;BYDAY=1SU;BYMONTH=4"));
            daylight.TZOffsetFrom = new UTC_Offset("-0500");
            daylight.TZOffsetTo = new UTC_Offset("-0400");
            daylight.TimeZoneName = "EDT";

            Event evt = iCal.Create<Event>();
            evt.Summary = "Test event";
            evt.Start = new iCalDateTime(2007, 1, 24, 8, 0, 0, tzid, iCal);
            evt.Duration = TimeSpan.FromHours(1);
            evt.End = new iCalDateTime(2007, 1, 24, 9, 0, 0, tzid, iCal);
            RecurrencePattern recur = new RecurrencePattern("FREQ=MONTHLY;INTERVAL=2;BYDAY=4WE");
            evt.AddRecurrencePattern(recur);

            List<Occurrence> occurrences = evt.GetOccurrences(
                new DateTime(2007, 1, 24), 
                new DateTime(2007, 12, 31));

            iCalDateTime[] DateTimes = new iCalDateTime[]
            {                
                new iCalDateTime(2007, 1, 24, 8, 0, 0, tzid, iCal),
                new iCalDateTime(2007, 3, 28, 8, 0, 0, tzid, iCal),
                new iCalDateTime(2007, 5, 23, 8, 0, 0, tzid, iCal),
                new iCalDateTime(2007, 7, 25, 8, 0, 0, tzid, iCal),
                new iCalDateTime(2007, 9, 26, 8, 0, 0, tzid, iCal),
                new iCalDateTime(2007, 11, 28, 8, 0, 0, tzid, iCal)
            };
            
            for (int i = 0; i < DateTimes.Length; i++)
                Assert.AreEqual(DateTimes[i], occurrences[i].Period.StartTime, "Event should occur on " + DateTimes[i]);

            Assert.AreEqual(
                DateTimes.Length,
                occurrences.Count,                
                "There should be exactly " + DateTimes.Length +
                " occurrences; there were " + occurrences.Count);
        }