Ejemplo n.º 1
0
        /// <summary>
        ///     Apply the time-filter to the VEVENT components.
        ///     A VEVENT component overlaps a given time range if the condition for the
        ///     corresponding component state specified in the table (pg64 RFC 4791) is satisfied.
        /// </summary>
        /// <param name="component">THe VTODO</param>
        /// <param name="start">The start time of the filter</param>
        /// <param name="end">The end datetime of the filter</param>
        /// <param name="expandedDates">The expaned dts by the RRULEs if any.</param>
        /// <returns>True if pass the filter, false otherwise.</returns>
        private static bool ApplyTimeFilterToVEVENT(this ICalendarComponent component, DateTime start, DateTime end,
                                                    IEnumerable <DateTime> expandedDates)
        {
            var compEndTimeProp = component.GetComponentProperty("DTEND");

            foreach (var DTSTART in expandedDates)
            {
                //VEVENT has the DTEND property? Y
                // VEVENT has the DURATION property? N
                // DURATION property value is greater than 0 seconds? N
                // DTSTART property is a DATE-TIME value? *
                if (compEndTimeProp != null)
                {
                    var DTEND = ((IValue <DateTime>)compEndTimeProp).Value;
                    if (start < DTEND && end > DTSTART)
                    {
                        return(true);
                    }
                }

                var durationProp = component.GetComponentProperty("DURATION");

                //VEVENT has the DTEND property? N
                // VEVENT has the DURATION property? Y
                if (durationProp != null)
                {
                    var DURATION            = ((IValue <DurationType>)durationProp).Value;
                    var DTSTARTplusDURATION = DTSTART.AddDuration(DURATION);

                    // DURATION property value is greater than 0 seconds? Y
                    // DTSTART property is a DATE-TIME value? *
                    if (DURATION.IsPositive)
                    {
                        if (start < DTSTARTplusDURATION && end > DTSTART)
                        {
                            return(true);
                        }
                    }
                    // DURATION property value is greater than 0 seconds? N
                    // DTSTART property is a DATE-TIME value? *
                    else
                    {
                        if (start <= DTSTART && end > DTSTART)
                        {
                            return(true);
                        }
                    }
                }

                //VEVENT has the DTEND property? N
                // VEVENT has the DURATION property? N
                // DURATION property value is greater than 0 seconds? N
                // DTSTART property is a DATE-TIME value? Y
                if (start <= DTSTART && end > DTSTART)
                {
                    return(true);
                }

                //VEVENT has the DTEND property? N
                // VEVENT has the DURATION property? N
                // DURATION property value is greater than 0 seconds? N
                // DTSTART property is a DATE-TIME value? N
                if (start < DTSTART.AddDays(1) && end > DTSTART)
                {
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Apply the time-filter to the VTODOs components.
        ///     A VTODO component overlaps a given time range if the condition for the
        ///     corresponding component state specified in the table (pg64 RFC 4791) is satisfied.
        /// </summary>
        /// <param name="component">The VTODO</param>
        /// <param name="start">The start time of the filter</param>
        /// <param name="end">The end datetime of the filter</param>
        /// <param name="expandedDates">The expaned dts by the RRULEs if any.</param>
        /// <returns>True if pass the filter, false otherwise.</returns>
        private static bool ApplyTimeFilterToVTODO(this ICalendarComponent component, DateTime start, DateTime end,
                                                   IEnumerable <DateTime> expandedDates)
        {
            var DURATION = component.GetComponentProperty("DURATION") == null
                ? null
                : ((IValue <DurationType>)component.GetComponentProperty("DURATION")).Value;
            var DUE = component.GetComponentProperty("DUE") == null
                ? null
                : ((IValue <Due>)component.GetComponentProperty("DUE")).Value;

            var COMPLETED = component.GetComponentProperty("COMPLETED") == null
                ? null
                : ((IValue <Completed>)component.GetComponentProperty("COMPLETED")).Value;

            var CREATED = component.GetComponentProperty("CREATED") == null
                ? null
                : ((IValue <Created>)component.GetComponentProperty("Created")).Value;


            //VTODO has the DTSTART property? Y
            if (expandedDates.Any())
            {
                foreach (var DTSTART in expandedDates)
                {
                    // VTODO has the DURATION property? Y
                    // VTODO has the DUE property? N
                    //  VTODO has the COMPLETED property? *
                    // VTODO has the CREATED property? *
                    if (DURATION != null && DUE == null)
                    {
                        var DTSTARTplusDURATION = DTSTART.AddDuration(DURATION);
                        if (start <= DTSTARTplusDURATION &&
                            (end > DTSTART || end > DTSTARTplusDURATION))
                        {
                            return(true);
                        }
                    }

                    // VTODO has the DURATION property? N
                    // VTODO has the DUE property? Y
                    //  VTODO has the COMPLETED property? *
                    // VTODO has the CREATED property? *
                    else if (DUE != null)
                    {
                        if ((start < DUE.Value || start <= DTSTART) &&
                            (end > DTSTART) || end >= DUE.Value)
                        {
                            return(true);
                        }
                    }

                    // VTODO has the DURATION property? N
                    // VTODO has the DUE property? N
                    //  VTODO has the COMPLETED property? *
                    // VTODO has the CREATED property? *
                    if (DUE == null && DURATION == null)
                    {
                        if (start <= DTSTART && end > DTSTART)
                        {
                            return(true);
                        }
                    }
                }
            }

            //VTODO has the DTSTART property? N
            else
            {
                // VTODO has the DURATION property? N
                // VTODO has the DUE property? Y
                //  VTODO has the COMPLETED property? *
                // VTODO has the CREATED property? *
                if (DUE != null && DURATION == null)
                {
                    if (start < DUE.Value && end >= DUE.Value)
                    {
                        return(true);
                    }
                }

                // VTODO has the DURATION property? N
                // VTODO has the DUE property? N
                //  VTODO has the COMPLETED property? Y
                // VTODO has the CREATED property? Y
                if (COMPLETED != null && CREATED != null)
                {
                    if ((start <= CREATED.Value || start <= COMPLETED.Value) &&
                        end >= CREATED.Value || end >= COMPLETED.Value)
                    {
                        return(true);
                    }
                }

                // VTODO has the DURATION property? N
                // VTODO has the DUE property? N
                //  VTODO has the COMPLETED property? Y
                // VTODO has the CREATED property? N
                else if (COMPLETED != null && CREATED == null)
                {
                    if (start <= COMPLETED.Value && end >= COMPLETED.Value)
                    {
                        return(true);
                    }
                }

                // VTODO has the DURATION property? N
                // VTODO has the DUE property? N
                //  VTODO has the COMPLETED property? N
                // VTODO has the CREATED property? Y
                else if (COMPLETED == null && CREATED != null)
                {
                    if (end > CREATED.Value)
                    {
                        return(true);
                    }
                }
            }
            // VTODO has the DURATION property? N
            // VTODO has the DUE property? N
            //  VTODO has the COMPLETED property? N
            // VTODO has the CREATED property? N
            return(true);
        }