Ejemplo n.º 1
0
        /// <summary>
        /// Evaluates this item to determine the dates and times for which it occurs/recurs.
        /// This method only evaluates items which occur/recur between <paramref name="FromDate"/>
        /// and <paramref name="ToDate"/>; therefore, if you require a list of items which
        /// occur outside of this range, you must specify a <paramref name="FromDate"/> and
        /// <paramref name="ToDate"/> which encapsulate the date(s) of interest.
        /// <note type="caution">
        ///     For events with very complex recurrence rules, this method may be a bottleneck
        ///     during processing time, especially when this method is called for a large number
        ///     of items, in sequence, or for a very large time span.
        /// </note>
        /// </summary>
        /// <param name="FromDate">The beginning date of the range to evaluate.</param>
        /// <param name="ToDate">The end date of the range to evaluate.</param>
        /// <returns>
        ///     An <see cref="ArrayList"/> containing a <see cref="Date_Time"/> object for
        ///     each date/time this item occurs/recurs.
        /// </returns>
        virtual public List <Period> Evaluate(Date_Time FromDate, Date_Time ToDate)
        {
            // Evaluate extra time periods, without re-evaluating ones that were already evaluated
            if ((EvalStart == null && EvalEnd == null) ||
                (ToDate == EvalStart) ||
                (FromDate == EvalEnd))
            {
                EvaluateRRule(FromDate, ToDate);
                EvaluateRDate(FromDate, ToDate);
                EvaluateExRule(FromDate, ToDate);
                EvaluateExDate(FromDate, ToDate);
                if (EvalStart == null || EvalStart > FromDate)
                {
                    EvalStart = FromDate.Copy();
                }
                if (EvalEnd == null || EvalEnd < ToDate)
                {
                    EvalEnd = ToDate.Copy();
                }
            }

            if (EvalStart != null && FromDate < EvalStart)
            {
                Evaluate(FromDate, EvalStart);
            }
            if (EvalEnd != null && ToDate > EvalEnd)
            {
                Evaluate(EvalEnd, ToDate);
            }

            Periods.Sort();

            foreach (Period p in Periods)
            {
                // Ensure the Kind of time is consistent with DTStart
                if (p.StartTime.Kind != DTStart.Kind)
                {
                    p.StartTime.Value = DateTime.SpecifyKind(p.StartTime.Value, DTStart.Kind);
                }
            }

            // Evaluate all Alarms for this component.
            foreach (Alarm alarm in Alarms)
            {
                alarm.Evaluate(this);
            }

            return(Periods);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Returns 'True' if the todo item is Active as of <paramref name="currDt"/>.
 /// An item is Active if it requires action of some sort.
 /// </summary>
 /// <param name="currDt">The date and time to test.</param>
 /// <returns>True if the item is Active as of <paramref name="currDt"/>, False otherwise.</returns>
 public bool IsActive(Date_Time currDt)
 {
     if (DTStart == null)
     {
         return(!IsCompleted(currDt) && !IsCancelled());
     }
     else if (currDt >= DTStart)
     {
         return(!IsCompleted(currDt) && !IsCancelled());
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns all occurrences of components of type T that start within the date range provided.
        /// All components occurring between <paramref name="startTime"/> and <paramref name="endTime"/>
        /// will be returned.
        /// </summary>
        /// <param name="startTime">The starting date range</param>
        /// <param name="endTime">The ending date range</param>
        virtual public List <Occurrence> GetOccurrences <T>(Date_Time startTime, Date_Time endTime) where T : RecurringComponent
        {
            List <Occurrence> occurrences = new List <Occurrence>();

            foreach (RecurringComponent rc in RecurringComponents)
            {
                if (rc is T)
                {
                    occurrences.AddRange(rc.GetOccurrences(startTime, endTime));
                }
            }

            occurrences.Sort();
            return(occurrences);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Retrieves the TimeZoneInfo object that contains information
        /// about the TimeZone, with the name of the current timezone,
        /// offset from UTC, etc.
        /// </summary>
        /// <param name="dt">The Date_Time object for which to retrieve the TimeZoneInfo</param>
        /// <returns>A TimeZoneInfo object for the specified Date_Time</returns>
        public TimeZoneInfo GetTimeZoneInfo(Date_Time dt)
        {
            TimeZoneInfo tzi = null;

            TimeSpan mostRecent = TimeSpan.MaxValue;

            foreach (TimeZoneInfo curr in TimeZoneInfos)
            {
                DateTime Start = new DateTime(dt.Year - 1, 1, 1, 0, 0, 0, DateTimeKind.Utc);
                DateTime End   = new DateTime(dt.Year + 1, 1, 1, 0, 0, 0, DateTimeKind.Utc);

                DateTime dtUTC = dt.Value;
                dtUTC = DateTime.SpecifyKind(dtUTC, DateTimeKind.Utc);

                if (curr.TZOffsetTo != null)
                {
                    int mult = curr.TZOffsetTo.Positive ? -1 : 1;
                    dtUTC      = dtUTC.AddHours(curr.TZOffsetTo.Hours * mult);
                    dtUTC      = dtUTC.AddMinutes(curr.TZOffsetTo.Minutes * mult);
                    dtUTC      = dtUTC.AddSeconds(curr.TZOffsetTo.Seconds * mult);
                    curr.Start = curr.Start.AddHours(curr.TZOffsetTo.Hours * mult);
                    curr.Start = curr.Start.AddMinutes(curr.TZOffsetTo.Minutes * mult);
                    curr.Start = curr.Start.AddSeconds(curr.TZOffsetTo.Seconds * mult);
                }

                // Determine the UTC occurrences of the Time Zone changes
                if (curr.EvalStart == null ||
                    curr.EvalEnd == null ||
                    dtUTC < curr.EvalStart.Value ||
                    dtUTC > curr.EvalEnd.Value)
                {
                    curr.Evaluate(Start, End);
                }

                foreach (Period p in curr.Periods)
                {
                    TimeSpan currentSpan = dtUTC - p.StartTime;
                    if (currentSpan.Ticks >= 0 &&
                        currentSpan.Ticks < mostRecent.Ticks)
                    {
                        mostRecent = currentSpan;
                        tzi        = curr;
                    }
                }
            }

            return(tzi);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Evaluates <see cref="Alarm"/>s for the given recurring component, <paramref name="rc"/>.
        /// This evaluation is based on the evaluation period for the <see cref="RecurringComponent"/>.
        /// </summary>
        /// <param name="rc">The </param>
        /// <returns></returns>
        virtual public List <AlarmOccurrence> Evaluate(RecurringComponent rc)
        {
            Occurrences.Clear();

            // If the trigger is relative, it can recur right along with
            // the recurring items, otherwise, it happens once and
            // only once (at a precise time).
            if (Trigger.IsRelative)
            {
                Duration d = null;
                foreach (Period p in rc.Periods)
                {
                    Date_Time dt = p.StartTime;
                    if (Trigger.Related == Trigger.TriggerRelation.END)
                    {
                        if (p.EndTime != null)
                        {
                            dt = p.EndTime;
                            if (d == null)
                            {
                                d = p.Duration;
                            }
                        }
                        // Use the "last-found" duration as a reference point
                        else if (d != null)
                        {
                            dt = p.StartTime + d;
                        }
                        else
                        {
                            throw new ArgumentException("Alarm trigger is relative to the END of the occurrence; however, the occurence has no discernible end.");
                        }
                    }

                    Occurrences.Add(new AlarmOccurrence(this, dt + Trigger.Duration, rc));
                }
            }
            else
            {
                Occurrences.Add(new AlarmOccurrence(this, Trigger.DateTime.Copy(), rc));
            }

            // If a REPEAT and DURATION value were specified,
            // then handle those repetitions here.
            AddRepeatedItems();

            return(Occurrences);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Use this method to determine if a todo item has been completed.
 /// This takes into account recurrence items and the previous date
 /// of completion, if any.
 /// </summary>
 /// <param name="DateTime">The date and time to test.</param>
 /// <returns>True if the todo item has been completed</returns>
 public bool IsCompleted(Date_Time currDt)
 {
     if (Status == Status.COMPLETED)
     {
         foreach (Date_Time dt in DateTimes)
         {
             if (dt > Completed && // The item has recurred after it was completed
                 currDt > dt)      // and the current date is after the recurrence date.
             {
                 return(false);
             }
         }
         return(true);
     }
     return(false);
 }
Ejemplo n.º 7
0
        public Date_TimeUTCSerializer(Date_Time dt)
            : base(dt)
        {
            // Make a copy of the Date_Time object, so we don't alter
            // the original
            DateTime = dt.Copy();

            // Set the Date_Time object to UTC time
            DateTime = DateTime.UTC;

            // Ensure time is serialized
            DateTime.HasTime = true;

            // FIXME: this is the old way we did it; remove when verified
            //DateTime.SetKind(DateTimeKind.Utc);
        }
Ejemplo n.º 8
0
        public override void CreateInitialize()
        {
            base.CreateInitialize();

            // Create a new UID for the component
            UID = UniqueComponent.NewUID();

            // Here, we don't simply set to DateTime.Now because DateTime.Now contains milliseconds, and
            // the iCalendar standard doesn't care at all about milliseconds.  Therefore, when comparing
            // two calendars, one generated, and one loaded from file, they may be functionally identical,
            // but be determined to be different due to millisecond differences.
            DateTime now = DateTime.Now;

            Created = new Date_Time(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second);
            DTStamp = Created.Copy();
        }
Ejemplo n.º 9
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);
            }
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Use this method to determine if an event occurs on a given date.
 /// <note type="caution">
 ///     This event should be called only after the <see cref="Evaluate"/>
 ///     method has calculated the dates for which this event occurs.
 /// </note>
 /// </summary>
 /// <param name="DateTime">The date to test.</param>
 /// <returns>True if the event occurs on the <paramref name="DateTime"/> provided, False otherwise.</returns>
 public bool OccursOn(Date_Time DateTime)
 {
     foreach (Period p in Periods)
     {
         if (p.StartTime.UTC.Date == DateTime.UTC.Date ||
             (p.StartTime.UTC.Date <= DateTime.UTC.Date &&
              p.EndTime.UTC.Date > DateTime.UTC.Date)) // Changed ">=" to ">"
         // NOTE: fixed bug as follows:
         // DTSTART;VALUE=DATE:20060704
         // DTEND;VALUE=DATE:20060705
         // Event.OccursOn(new Date_Time(2006, 7, 5)); // Evals to true; should be false
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Automatically derives property values based on others it
        /// contains, to provide a more "complete" object.
        /// </summary>
        /// <param name="e"></param>
        public override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            // Automatically determine Duration from DTEnd, or DTEnd from Duration
            if (DTStart != null)
            {
                if (DTEnd != null && Duration == null)
                {
                    Duration = new Duration(DTEnd.Value - DTStart.Value);
                }
                else if (DTEnd == null && Duration != null)
                {
                    DTEnd = new Date_Time(DTStart.Value + Duration.Value);
                }
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Returns all occurrences of this component that start within the date range provided.
        /// All components occurring between <paramref name="startTime"/> and <paramref name="endTime"/>
        /// will be returned.
        /// </summary>
        /// <param name="startTime">The starting date range</param>
        /// <param name="endTime">The ending date range</param>
        virtual public List <Occurrence> GetOccurrences(Date_Time startTime, Date_Time endTime)
        {
            List <Occurrence> occurrences = new List <Occurrence>();
            List <Period>     periods     = Evaluate(startTime, endTime);

            foreach (Period p in periods)
            {
                if (p.StartTime >= startTime &&
                    p.StartTime <= endTime)
                {
                    occurrences.Add(new Occurrence(this, p));
                }
            }

            occurrences.Sort();
            return(occurrences);
        }
Ejemplo n.º 13
0
        public override List <Period> Evaluate(Date_Time FromDate, Date_Time ToDate)
        {
            // TODO items can only recur if a start date is specified
            if (DTStart != null)
            {
                // Add the todo itself, before recurrence rules are evaluated
                Period startPeriod = new Period(DTStart);
                if (DTStart != null &&
                    !Periods.Contains(startPeriod))
                {
                    Periods.Add(startPeriod);
                }

                return(base.Evaluate(FromDate, ToDate));
            }
            return(new List <Period>());
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Automatically derives property values based on others it
        /// contains, to provide a more "complete" object.
        /// </summary>
        /// <param name="e"></param>
        public override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            // Automatically determine Duration from Due, or Due from Duration
            if (DTStart != null)
            {
                if (Due != null && Duration == null)
                {
                    Duration = new Duration(Due - DTStart);
                }
                else if (Due == null && Duration != null)
                {
                    Due = DTStart + Duration;
                }
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Handles the repetitions that occur from the <c>REPEAT</c> and
        /// <c>DURATION</c> properties.  Each recurrence of the alarm will
        /// have its own set of generated repetitions.
        /// </summary>
        virtual protected void AddRepeatedItems()
        {
            if (Repeat != null)
            {
                int len = Occurrences.Count;
                for (int i = 0; i < len; i++)
                {
                    AlarmOccurrence ao        = Occurrences[i];
                    Date_Time       AlarmTime = ao.DateTime.Copy();

                    for (int j = 0; j < Repeat; j++)
                    {
                        AlarmTime += Duration;
                        Occurrences.Add(new AlarmOccurrence(this, AlarmTime.Copy(), ao.Component));
                    }
                }
            }
        }
Ejemplo n.º 16
0
 /// <summary>
 /// Evalates the RDate component, and adds each specified DateTime or
 /// Period to the <see cref="Periods"/> collection.
 /// </summary>
 /// <param name="FromDate">The beginning date of the range to evaluate.</param>
 /// <param name="ToDate">The end date of the range to evaluate.</param>
 virtual protected void EvaluateRDate(Date_Time FromDate, Date_Time ToDate)
 {
     // Handle RDATEs
     if (RDate != null)
     {
         foreach (RDate rdate in RDate)
         {
             List <Period> periods = rdate.Evaluate(DTStart, FromDate, ToDate);
             foreach (Period p in periods)
             {
                 if (p != null && !Periods.Contains(p))
                 {
                     Periods.Add(p);
                 }
             }
         }
     }
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Evaulates the RRule component, and adds each specified DateTime
 /// to the <see cref="DateTimes"/> collection.
 /// </summary>
 /// <param name="FromDate">The beginning date of the range to evaluate.</param>
 /// <param name="ToDate">The end date of the range to evaluate.</param>
 virtual protected void EvaluateRRule(Date_Time FromDate, Date_Time ToDate)
 {
     // Handle RRULEs
     if (RRule != null)
     {
         foreach (Recur rrule in RRule)
         {
             ArrayList DateTimes = rrule.Evaluate(DTStart, FromDate, ToDate);
             foreach (Date_Time dt in DateTimes)
             {
                 if (!this.DateTimes.Contains(dt))
                 {
                     this.DateTimes.Add(dt);
                 }
             }
         }
     }
 }
Ejemplo n.º 18
0
 /// <summary>
 /// Evaulates the ExRule component, and excludes each specified DateTime
 /// from the <see cref="DateTimes"/> collection.
 /// </summary>
 /// <param name="FromDate">The beginning date of the range to evaluate.</param>
 /// <param name="ToDate">The end date of the range to evaluate.</param>
 virtual protected void EvaluateExRule(Date_Time FromDate, Date_Time ToDate)
 {
     // Handle EXRULEs
     if (ExRule != null)
     {
         foreach (Recur exrule in ExRule)
         {
             ArrayList DateTimes = exrule.Evaluate(DTStart, FromDate, ToDate);
             foreach (Date_Time dt in DateTimes)
             {
                 if (this.DateTimes.Contains(dt))
                 {
                     this.DateTimes.Remove(dt);
                 }
             }
         }
     }
 }
Ejemplo n.º 19
0
        /// <summary>
        /// Evaluates this event to determine the dates and times for which the event occurs.
        /// This method only evaluates events which occur between <paramref name="FromDate"/>
        /// and <paramref name="ToDate"/>; therefore, if you require a list of events which
        /// occur outside of this range, you must specify a <paramref name="FromDate"/> and
        /// <paramref name="ToDate"/> which encapsulate the date(s) of interest.
        /// <note type="caution">
        ///     For events with very complex recurrence rules, this method may be a bottleneck
        ///     during processing time, especially when this method in called for a large number
        ///     of events, in sequence, or for a very large time span.
        /// </summary>
        /// <param name="FromDate">The beginning date of the range to evaluate.</param>
        /// <param name="ToDate">The end date of the range to evaluate.</param>
        /// <returns></returns>
        public override List <Period> Evaluate(Date_Time FromDate, Date_Time ToDate)
        {
            // Make sure Duration is not null by now
            if (Duration == null)
            {
                // If a DTEnd was not provided, set one!
                if (DTEnd == null)
                {
                    DTEnd = DTStart.Copy();
                }
                Duration = DTEnd - DTStart;
            }

            // Add the event itself, before recurrence rules are evaluated
            // NOTE: this fixes a bug where (if evaluated multiple times)
            // a period can be added to the Periods collection multiple times.
            Period period = new Period(DTStart, Duration);

            if (!Periods.Contains(period))
            {
                Periods.Add(period);
            }

            // Evaluate recurrences normally
            base.Evaluate(FromDate, ToDate);

            // Ensure each period has a duration
            foreach (Period p in Periods)
            {
                if (p.EndTime == null)
                {
                    p.Duration = Duration;
                    p.EndTime  = p.StartTime + Duration;
                }
                // Ensure the Kind of time is consistent with DTStart
                else if (p.EndTime.Kind != DTStart.Kind)
                {
                    p.EndTime.Value = new DateTime(p.EndTime.Year, p.EndTime.Month, p.EndTime.Day,
                                                   p.EndTime.Hour, p.EndTime.Minute, p.EndTime.Second, DTStart.Kind);
                }
            }

            return(Periods);
        }
Ejemplo n.º 20
0
 /// <summary>
 /// Evaulates the ExRule component, and excludes each specified DateTime
 /// from the <see cref="Periods"/> collection.
 /// </summary>
 /// <param name="FromDate">The beginning date of the range to evaluate.</param>
 /// <param name="ToDate">The end date of the range to evaluate.</param>
 virtual protected void EvaluateExRule(Date_Time FromDate, Date_Time ToDate)
 {
     // Handle EXRULEs
     if (ExRule != null)
     {
         foreach (Recur exrule in ExRule)
         {
             List <Date_Time> DateTimes = exrule.Evaluate(DTStart, FromDate, ToDate);
             foreach (Date_Time dt in DateTimes)
             {
                 Period p = new Period(dt);
                 if (this.Periods.Contains(p))
                 {
                     this.Periods.Remove(p);
                 }
             }
         }
     }
 }
Ejemplo n.º 21
0
 /// <summary>
 /// Evaulates the RRule component, and adds each specified DateTime
 /// to the <see cref="Periods"/> collection.
 /// </summary>
 /// <param name="FromDate">The beginning date of the range to evaluate.</param>
 /// <param name="ToDate">The end date of the range to evaluate.</param>
 protected void EvaluateRRule(Date_Time FromDate, Date_Time ToDate)
 {
     // Handle RRULEs
     if (RRule != null)
     {
         foreach (Recur rrule in RRule)
         {
             ArrayList DateTimes = rrule.Evaluate(DTStart, FromDate, ToDate);
             foreach (Date_Time dt in DateTimes)
             {
                 Period p = new Period(dt, (TimeSpan)Duration);
                 if (!Periods.Contains(p))
                 {
                     Periods.Add(p);
                 }
             }
         }
     }
 }
Ejemplo n.º 22
0
        public void TestTodoCompleted(string calendar, ArrayList items)
        {
            iCalendar iCal = iCalendar.LoadFromFile(@"Calendars\Todo\" + calendar);
            Program.TestCal(iCal);
            DDay.iCal.Components.Todo todo = (DDay.iCal.Components.Todo)iCal.Todos[0];
            todo.Evaluate(new Date_Time(2006, 7, 28, tzid, iCal), new Date_Time(2010, 1, 1, tzid, iCal));

            for (int i = 0; i < items.Count; i += 2)
            {
                Date_Time dt = (Date_Time)items[i];
                dt.iCalendar = iCal;
                dt.TZID = tzid;

                bool tf = (bool)items[i + 1];
                if (tf)
                    Assert.IsTrue(todo.IsCompleted(dt), "Todo should be completed at " + dt);
                else Assert.IsFalse(todo.IsCompleted(dt), "Todo should not be completed at " + dt);
            }
        }
Ejemplo n.º 23
0
 /// <summary>
 /// Evaulates the ExRule component, and excludes each specified DateTime
 /// from the <see cref="Periods"/> collection.
 /// </summary>
 /// <param name="FromDate">The beginning date of the range to evaluate.</param>
 /// <param name="ToDate">The end date of the range to evaluate.</param>
 protected void EvaluateExRule(Date_Time FromDate, Date_Time ToDate)
 {
     // Handle EXRULEs
     if (ExRule != null)
     {
         foreach (Recur exrule in ExRule)
         {
             ArrayList DateTimes = exrule.Evaluate(DTStart, FromDate, ToDate);
             foreach (Date_Time dt in DateTimes)
             {
                 Period p = new Period(dt, (TimeSpan)Duration);
                 if (Periods.Contains(p))
                 {
                     Periods.Remove(p);
                 }
             }
         }
     }
 }
Ejemplo n.º 24
0
 /// <summary>
 /// Use this method to determine if an event occurs on a given date.
 /// <note type="caution">
 ///     This event should be called only after the <see cref="Evaluate"/>
 ///     method has calculated the dates for which this event occurs.
 /// </note>
 /// </summary>
 /// <param name="DateTime">The date to test.</param>
 /// <returns>True if the event occurs on the <paramref name="DateTime"/> provided, False otherwise.</returns>
 public bool OccursOn(Date_Time DateTime)
 {
     foreach (Period p in Periods)
     {
         // NOTE: removed UTC from date checks, since a date is a date.
         if (p.StartTime.Date == DateTime.Date ||                        // It's the start date
             (p.StartTime.Date <= DateTime.Date &&                       // It's after the start date AND
              (p.EndTime.HasTime && p.EndTime.Date >= DateTime.Date ||   // an end time was specified, and it's before then
               (!p.EndTime.HasTime && p.EndTime.Date > DateTime.Date)))) // an end time was not specified, and it's before the end date
         // NOTE: fixed bug as follows:
         // DTSTART;VALUE=DATE:20060704
         // DTEND;VALUE=DATE:20060705
         // Event.OccursOn(new Date_Time(2006, 7, 5)); // Evals to true; should be false
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 25
0
        /// <summary>
        /// Evaulates the RRule component, and adds each specified Period
        /// to the <see cref="Periods"/> collection.
        /// </summary>
        /// <param name="FromDate">The beginning date of the range to evaluate.</param>
        /// <param name="ToDate">The end date of the range to evaluate.</param>
        virtual protected void EvaluateRRule(Date_Time FromDate, Date_Time ToDate)
        {
            // Handle RRULEs
            if (RRule != null)
            {
                foreach (Recur rrule in RRule)
                {
                    List <Date_Time> DateTimes = rrule.Evaluate(DTStart, FromDate, ToDate);
                    foreach (Date_Time dt in DateTimes)
                    {
                        Period p = new Period(dt);

                        if (!Periods.Contains(p))
                        {
                            this.Periods.Add(p);
                        }
                    }
                }
            }
        }
Ejemplo n.º 26
0
 /// <summary>
 /// Use this method to determine if an event occurs on a given date.
 /// <note type="caution">
 ///     This event should be called only after the <see cref="Evaluate"/>
 ///     method has calculated the dates for which this event occurs.
 /// </note>
 /// </summary>
 /// <param name="DateTime">The date to test.</param>
 /// <returns>True if the event occurs on the <paramref name="DateTime"/> provided, False otherwise.</returns>
 public bool OccursOn(Date_Time DateTime)
 {
     foreach (Period p in Periods)
     {
         // NOTE: removed UTC from date checks, since a date is a date.
         if (p.StartTime.Date == DateTime.Date ||    // It's the start date
             (p.StartTime.Date <= DateTime.Date &&   // It's after the start date AND
              (p.EndTime.Date > DateTime.Date ||     // It's less than the end date OR
               // It's equal to the end date, and the end date is not the same as the start date
               (p.StartTime.Date != p.EndTime.Date && p.EndTime.Date == DateTime.Date))))
         {
             // NOTE: fixed bug as follows:
             // DTSTART;VALUE=DATE:20060704
             // DTEND;VALUE=DATE:20060705
             // Event.OccursOn(new Date_Time(2006, 7, 5)); // Evals to true; should be false
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 27
0
        /// <summary>
        /// Evaluates this event to determine the dates and times for which the event occurs.
        /// This method only evaluates events which occur between <paramref name="FromDate"/>
        /// and <paramref name="ToDate"/>; therefore, if you require a list of events which
        /// occur outside of this range, you must specify a <paramref name="FromDate"/> and
        /// <paramref name="ToDate"/> which encapsulate the date(s) of interest.
        /// <note type="caution">
        ///     For events with very complex recurrence rules, this method may be a bottleneck
        ///     during processing time, especially when this method in called for a large number
        ///     of events, in sequence, or for a very large time span.
        /// </summary>
        /// <param name="FromDate">The beginning date of the range to evaluate.</param>
        /// <param name="ToDate">The end date of the range to evaluate.</param>
        /// <returns></returns>
        public override ArrayList Evaluate(Date_Time FromDate, Date_Time ToDate)
        {
            // Add the event itself, before recurrence rules are evaluated
            Periods.Add(new Period(DTStart, (TimeSpan)Duration));

            // Evaluate recurrences normally
            base.Evaluate(FromDate, ToDate);

            // Convert each calculated Date_Time into a Period.
            foreach (Date_Time dt in DateTimes)
            {
                Period p = new Period(dt, Duration);
                if (!Periods.Contains(p))
                {
                    Periods.Add(p);
                }
            }

            return(Periods);
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Adds a single recurrence for this recurring component.
        /// </summary>
        /// <param name="dt">The date/time when this component will recur.</param>
        public void AddSingleRecurrence(Date_Time dt)
        {
            RDate rdate = new RDate();

            rdate.Name = "RDATE";
            rdate.Add(dt);

            rdate.Parent = this;

            if (RDate != null)
            {
                RDate[] dates = new RDate[RDate.Length + 1];
                RDate.CopyTo(dates, 0);
                dates[dates.Length - 1] = rdate;
                RDate = dates;
            }
            else
            {
                RDate = new RDate[] { rdate }
            };
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Use this method to determine if a todo item has been completed.
        /// This takes into account recurrence items and the previous date
        /// of completion, if any.
        /// </summary>
        /// <param name="DateTime">The date and time to test.</param>
        /// <returns>True if the todo item has been completed</returns>
        public bool IsCompleted(Date_Time currDt)
        {
            if (Status == TodoStatus.COMPLETED)
            {
                if (Completed == null)
                {
                    return(true);
                }

                foreach (Period p in Periods)
                {
                    if (p.StartTime > Completed && // The item has recurred after it was completed
                        currDt >= p.StartTime)     // and the current date is after or on the recurrence date.
                    {
                        return(false);
                    }
                }
                return(true);
            }
            return(false);
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Adds a single exception for this recurring component
        /// </summary>
        /// <param name="recur">The date/time when this component will NOT recur.</param>
        public void AddSingleException(Date_Time dt)
        {
            RDate exdate = new RDate();

            exdate.Name = "EXDATE";
            exdate.Add(dt);

            exdate.Parent = this;

            if (ExDate != null)
            {
                RDate[] dates = new RDate[ExDate.Length + 1];
                ExDate.CopyTo(dates, 0);
                dates[dates.Length - 1] = exdate;
                ExDate = dates;
            }
            else
            {
                ExDate = new RDate[] { exdate }
            };
        }