/// <summary>
        /// "Flattens" component recurrences that occur in the given date into a series of equivalent objects.
        /// </summary>
        /// <param name="dt">The date on which the event recurs</param>
        /// <returns>A list of <see cref="Event"/>s if they could be flattened, null otherwise.</returns>
        virtual public IEnumerable <RecurringComponent> FlattenRecurrencesOn(Date_Time dt)
        {
            // Create a dummy iCalendar to hold our flattened component
            iCalendar iCal = new iCalendar();

            if (Start.TZID != null)
            {
                // Place the time zone into our dummy iCalendar
                DDay.iCal.Components.TimeZone tz = iCalendar.GetTimeZone(Start.TZID);
                if (tz != null)
                {
                    tz.Copy(iCal);
                }
            }

            // Iterate through each period to find all occurrences on this date
            foreach (Period p in Periods)
            {
                // Check to see if this occurrence is on the same date
                if (p.StartTime.Date.Equals(dt.Date))
                {
                    // Copy the component into the dummy iCalendar
                    RecurringComponent rc = (RecurringComponent)Copy(iCal);

                    rc.Start  = p.StartTime.Copy();
                    rc.RRule  = new Recur[0];
                    rc.RDate  = new RDate[0];
                    rc.ExRule = new Recur[0];
                    rc.ExDate = new RDate[0];

                    yield return(rc);
                }
            }
        }
 /// <summary>
 /// Retrieves the <see cref="DDay.iCal.Components.TimeZone" /> object for the specified
 /// <see cref="TZID"/> (Time Zone Identifier).
 /// </summary>
 /// <param name="tzid">A valid <see cref="TZID"/> object, or a valid <see cref="TZID"/> string.</param>
 /// <returns>A <see cref="TimeZone"/> object for the <see cref="TZID"/>.</returns>
 public DDay.iCal.Components.TimeZone GetTimeZone(TZID tzid)
 {
     foreach (iCalendar iCal in this)
     {
         DDay.iCal.Components.TimeZone tz = iCal.GetTimeZone(tzid);
         if (tz != null)
         {
             return(tz);
         }
     }
     return(null);
 }
Example #3
0
        public void TIMEZONE2()
        {
            //
            // First, check against the VALUE parameter; it must be absent in DTSTART
            //

            iCalendar iCal = iCalendar.LoadFromFile(@"Calendars\Serialization\TIMEZONE2.ics");

            DDay.iCal.Components.TimeZone tz = iCal.TimeZones[0];
            foreach (DDay.iCal.Components.TimeZone.TimeZoneInfo tzi in tz.TimeZoneInfos)
            {
                tzi.Start = new Date_Time(2007, 1, 1);
            }

            iCalendarSerializer serializer = new iCalendarSerializer(iCal);

            serializer.Serialize(@"Calendars\Serialization\Temp\TIMEZONE2.ics");

            iCal = iCalendar.LoadFromFile(@"Calendars\Serialization\Temp\TIMEZONE2.ics");
            tz   = iCal.TimeZones[0];

            foreach (DDay.iCal.Components.TimeZone.TimeZoneInfo tzi in tz.TimeZoneInfos)
            {
                ContentLine cl = tzi.Start.ContentLine;
                Assert.IsFalse(cl.Parameters.ContainsKey("VALUE"), "\"DTSTART\" property MUST be represented in local time in timezones");
            }

            //
            // Next, check against UTC time; DTSTART must be presented in local time
            //
            iCal = iCalendar.LoadFromFile(@"Calendars\Serialization\TIMEZONE2.ics");

            tz = iCal.TimeZones[0];
            foreach (DDay.iCal.Components.TimeZone.TimeZoneInfo tzi in tz.TimeZoneInfos)
            {
                tzi.Start = DateTime.Now.ToUniversalTime();
            }

            serializer = new iCalendarSerializer(iCal);
            serializer.Serialize(@"Calendars\Serialization\Temp\TIMEZONE2.ics");

            iCal = iCalendar.LoadFromFile(@"Calendars\Serialization\Temp\TIMEZONE2.ics");
            tz   = iCal.TimeZones[0];

            foreach (DDay.iCal.Components.TimeZone.TimeZoneInfo tzi in tz.TimeZoneInfos)
            {
                ContentLine cl = tzi.Start.ContentLine;
                Assert.IsFalse(cl.Parameters.ContainsKey("VALUE"), "\"DTSTART\" property MUST be represented in local time in timezones");
            }
        }
Example #4
0
        public void TIMEZONE1()
        {
            iCalendar iCal = iCalendar.LoadFromFile(@"Calendars\Serialization\TIMEZONE1.ics");

            DDay.iCal.Components.TimeZone tz = iCal.TimeZones[0];
            tz.Last_Modified = new Date_Time(2007, 1, 1);

            iCalendarSerializer serializer = new iCalendarSerializer(iCal);

            serializer.Serialize(@"Calendars\Serialization\Temp\TIMEZONE1.ics");

            iCal = iCalendar.LoadFromFile(@"Calendars\Serialization\Temp\TIMEZONE1.ics");
            tz   = iCal.TimeZones[0];

            ContentLine cl = tz.Last_Modified.ContentLine;

            Assert.IsFalse(cl.Parameters.ContainsKey("VALUE"), "The \"VALUE\" parameter is not allowed on \"LAST-MODIFIED\"");
        }
        /// <summary>
        /// "Flattens" component recurrences into a series of equivalent objects.
        /// </summary>
        /// <returns>A list of <see cref="Event"/>s if they could be flattened, null otherwise.</returns>
        virtual public IEnumerable <RecurringComponent> FlattenRecurrences()
        {
            // Create a dummy iCalendar to hold our flattened component
            iCalendar iCal = new iCalendar();

            if (Start.TZID != null)
            {
                // Place the time zone into our dummy iCalendar
                DDay.iCal.Components.TimeZone tz = iCalendar.GetTimeZone(Start.TZID);
                if (tz != null)
                {
                    tz.Copy(iCal);
                }
            }

            // Iterate through each period to find all occurrences on this date
            foreach (Period p in Periods)
            {
                yield return(FlattenInstance(iCal, p));
            }
        }