예제 #1
2
파일: Program.cs 프로젝트: xxjeng/nuxleus
        /// <summary>
        /// Displays the calendar in the time zone identified by <paramref name="tzid"/>.
        /// </summary>
        static void ShowCalendar(iCalendar iCal, string tzid)
        {
            iCalDateTime start = new iCalDateTime(2007, 3, 1);
            iCalDateTime end = new iCalDateTime(2007, 4, 1).AddSeconds(-1);

            List<Occurrence> occurrences = iCal.GetOccurrences(start, end);

            Console.WriteLine("====Events/Todos/Journal Entries in " + tzid + "====");
            foreach (Occurrence o in occurrences)
            {
                Console.WriteLine(
                    o.Period.StartTime.ToTimeZone(tzid).ToString("ddd, MMM d - h:mm") + " to " +
                    o.Period.EndTime.ToTimeZone(tzid).ToString("h:mm tt") + Environment.NewLine +
                    o.Component.Summary + Environment.NewLine);
            }

            Console.WriteLine("====Alarms in " + tzid + "====");
            foreach (RecurringComponent rc in iCal.RecurringComponents)
            {
                foreach (AlarmOccurrence ao in rc.PollAlarms(start, end))
                {
                    Console.WriteLine(
                        "Alarm: " +
                        ao.DateTime.ToTimeZone(tzid).ToString("ddd, MMM d - h:mm") + ": " +
                        ao.Alarm.Summary);
                }
            }

            Console.WriteLine();
        }
예제 #2
0
        public void YearlyComplex1()
        {
            IICalendar iCal = iCalendar.LoadFromFile(@"Calendars\Recurrence\YearlyComplex1.ics")[0];
            ProgramTest.TestCal(iCal);
            IEvent evt = iCal.Events[0];
            IList<Occurrence> occurrences = evt.GetOccurrences(
                new iCalDateTime(2006, 1, 1, tzid),
                new iCalDateTime(2011, 1, 1, tzid));

            IDateTime dt = new iCalDateTime(2007, 1, 1, 8, 30, 0, tzid);
            int i = 0;

            while (dt.Year < 2011)
            {
                if ((dt.GreaterThan(evt.Start)) &&
                    (dt.Year % 2 == 1) && // Every-other year from 2005
                    (dt.Month == 1) &&
                    (dt.DayOfWeek == DayOfWeek.Sunday))
                {
                    IDateTime dt1 = dt.AddHours(1);
                    Assert.AreEqual(dt, occurrences[i].Period.StartTime, "Event should occur at " + dt);
                    Assert.AreEqual(dt1, occurrences[i + 1].Period.StartTime, "Event should occur at " + dt);
                    i += 2;
                }

                dt = dt.AddDays(1);
            }
        }
예제 #3
0
        /// <summary>
        /// Evalates the ExDate component, and excludes each specified DateTime or
        /// Period 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 EvaluateExDate(iCalDateTime FromDate, iCalDateTime ToDate)
        {
            // Handle EXDATEs
            if (ExDate != null)
            {
                foreach (RecurrenceDates exdate in ExDate)
                {
                    List <Period> periods = exdate.Evaluate(DTStart, FromDate, ToDate);
                    foreach (Period p in periods)
                    {
                        // If no time was provided for the ExDate, then it excludes the entire day
                        if (!p.StartTime.HasTime || (p.EndTime != null && !p.EndTime.HasTime))
                        {
                            p.MatchesDateOnly = true;
                        }

                        if (p != null)
                        {
                            while (Periods.Contains(p))
                            {
                                Periods.Remove(p);
                            }
                        }
                    }
                }
            }
        }
예제 #4
0
        public void TestTodoActive(string calendar, ArrayList items, params int[] numPeriods)
        {
            iCalendar iCal = iCalendar.LoadFromFile(@"Calendars\Todo\" + calendar);

            ProgramTest.TestCal(iCal);
            DDay.iCal.Components.Todo todo = (DDay.iCal.Components.Todo)iCal.Todos[0];

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

                bool tf = (bool)items[i + 1];
                if (tf)
                {
                    Assert.IsTrue(todo.IsActive(dt), "Todo should be active at " + dt);
                }
                else
                {
                    Assert.IsFalse(todo.IsActive(dt), "Todo should not be active at " + dt);
                }
            }

            if (numPeriods != null &&
                numPeriods.Length > 0)
            {
                Assert.AreEqual(
                    numPeriods[0],
                    todo.Periods.Count,
                    "Todo should have " + numPeriods[0] + " occurrences after evaluation; it had " + todo.Periods.Count);
            }
        }
예제 #5
0
 /// <summary>
 /// Use this method to determine if an event begins at a given date and time.
 /// </summary>
 /// <param name="DateTime">The date and time to test.</param>
 /// <returns>True if the event begins at the given date and time</returns>
 virtual public bool OccursAt(iCalDateTime DateTime)
 {            
     foreach (Period p in Periods)
         if (p.StartTime.Equals(DateTime))
             return true;
     return false;
 }
예제 #6
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.
        /// </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></returns>                
        internal override List<Period> Evaluate(iCalDateTime FromDate, iCalDateTime ToDate)
        {
            // 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);
            // Ensure the period does not already exist in our collection
            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;
                    if (p.Duration != null)
                        p.EndTime = p.StartTime + Duration;
                    else p.EndTime = p.StartTime;
                }
                // Ensure the Kind of time is consistent with DTStart
                p.EndTime.IsUniversalTime = DTStart.IsUniversalTime;
            }

            return Periods;
        }
예제 #7
0
        public void GOOGLE1()
        {
            TZID      tzid = "Europe/Berlin";
            iCalendar iCal = iCalendar.LoadFromFile(@"Calendars/General/GoogleCalendar.ics");
            Event     evt  = iCal.Events["*****@*****.**"];

            Assert.IsNotNull(evt);

            iCalDateTime      dtStart     = new iCalDateTime(2006, 12, 18, tzid, iCal);
            iCalDateTime      dtEnd       = new iCalDateTime(2006, 12, 23, tzid, iCal);
            List <Occurrence> occurrences = iCal.GetOccurrences(dtStart, dtEnd);

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

            for (int i = 0; i < DateTimes.Length; i++)
            {
                Assert.AreEqual(DateTimes[i], occurrences[i].Period.StartTime, "Event should occur at " + DateTimes[i]);
            }

            Assert.IsTrue(occurrences.Count == DateTimes.Length, "There should be exactly " + DateTimes.Length + " occurrences; there were " + occurrences.Count);
        }
예제 #8
0
        /// <summary>
        /// Displays the calendar in the time zone identified by <paramref name="tzid"/>.
        /// </summary>
        static void ShowCalendar(iCalendar iCal, string tzid)
        {
            iCalDateTime start = new iCalDateTime(2007, 3, 1);
            iCalDateTime end   = new iCalDateTime(2007, 4, 1).AddSeconds(-1);

            List <Occurrence> occurrences = iCal.GetOccurrences(start, end);

            Console.WriteLine("====Events/Todos/Journal Entries in " + tzid + "====");
            foreach (Occurrence o in occurrences)
            {
                Console.WriteLine(
                    o.Period.StartTime.ToTimeZone(tzid).ToString("ddd, MMM d - h:mm") + " to " +
                    o.Period.EndTime.ToTimeZone(tzid).ToString("h:mm tt") + Environment.NewLine +
                    o.Component.Summary + Environment.NewLine);
            }

            Console.WriteLine("====Alarms in " + tzid + "====");
            foreach (RecurringComponent rc in iCal.RecurringComponents)
            {
                foreach (AlarmOccurrence ao in rc.PollAlarms(start, end))
                {
                    Console.WriteLine(
                        "Alarm: " +
                        ao.DateTime.ToTimeZone(tzid).ToString("ddd, MMM d - h:mm") + ": " +
                        ao.Alarm.Summary);
                }
            }

            Console.WriteLine();
        }
예제 #9
0
        public void TestAlarm(string Calendar, List <iCalDateTime> Dates, iCalDateTime Start, iCalDateTime End)
        {
            iCalendar iCal = iCalendar.LoadFromFile(@"Calendars\Alarm\" + Calendar);

            Program.TestCal(iCal);
            Event evt = iCal.Events[0];

            Start.iCalendar = iCal;
            Start.TZID      = tzid;
            End.iCalendar   = iCal;
            End.TZID        = tzid;

            for (int i = 0; i < Dates.Count; i++)
            {
                Dates[i].TZID      = tzid;
                Dates[i].iCalendar = iCal;
            }

            // Poll all alarms that occurred between Start and End
            List <AlarmOccurrence> alarms = evt.PollAlarms(Start, End);

            foreach (AlarmOccurrence alarm in alarms)
            {
                Assert.IsTrue(Dates.Contains(alarm.DateTime), "Alarm triggers at " + alarm.Period.StartTime + ", but it should not.");
            }
            Assert.IsTrue(Dates.Count == alarms.Count, "There were " + alarms.Count + " alarm occurrences; there should have been " + Dates.Count + ".");
        }
예제 #10
0
        public void TestTodoActive(string calendar, ArrayList items, params int[] numPeriods)
        {
            IICalendar iCal = iCalendar.LoadFromFile(@"Calendars\Todo\" + calendar)[0];

            ProgramTest.TestCal(iCal);
            ITodo todo = iCal.Todos[0];

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

                bool tf = (bool)items[i + 1];
                if (tf)
                {
                    Assert.IsTrue(todo.IsActive(dt), "Todo should be active at " + dt);
                }
                else
                {
                    Assert.IsFalse(todo.IsActive(dt), "Todo should not be active at " + dt);
                }
            }

            if (numPeriods != null &&
                numPeriods.Length > 0)
            {
                IEvaluator evaluator = todo.GetService(typeof(IEvaluator)) as IEvaluator;
                Assert.IsNotNull(evaluator);
                Assert.AreEqual(
                    numPeriods[0],
                    evaluator.Periods.Count,
                    "Todo should have " + numPeriods[0] + " occurrences after evaluation; it had " + evaluator.Periods.Count);
            }
        }
예제 #11
0
        /// <summary>
        /// Gets the occurrences.
        /// </summary>
        /// <param name="startTime">The start time.</param>
        /// <param name="endTime">The end time.</param>
        /// <remarks> Вычисляет все экземпляры рекурсивного события в соотв с паттерном рекурсии. С учетом exception event.
        /// </remarks>
        /// <returns></returns>
        public override List <Occurrence> GetOccurrences(iCalDateTime startTime, iCalDateTime endTime)
        {
            //Очищаем кеш повторений
            ClearEvaluation();

            List <Occurrence> retVal = base.GetOccurrences(startTime, endTime);

            if (RecurrenceException != null)
            {
                foreach (McEvent exception in RecurrenceException)
                {
                    if (exception.Recurrence_ID != null)
                    {
                        //Start = RecurrenceId, Duration = Parent event duration
                        Occurrence exceptionOccur = new Occurrence(null, new Period(exception.Recurrence_ID, this.Duration));
                        //remove exception from orig occurrences list
                        if (retVal.Contains(exceptionOccur))
                        {
                            retVal.Remove(exceptionOccur);
                        }
                    }
                }
            }
            return(retVal);
        }
예제 #12
0
        public void SystemTimeZone2()
        {
            System.TimeZoneInfo tzi = System.TimeZoneInfo.FindSystemTimeZoneById("Mountain Standard Time");
            Assert.IsNotNull(tzi);

            iCalendar iCal = new iCalendar();
            ITimeZone tz   = iCal.AddTimeZone(tzi);

            Assert.IsNotNull(tz);

            iCalendarSerializer serializer = new iCalendarSerializer();

            serializer.Serialize(iCal, @"Calendars\Serialization\SystemTimeZone2.ics");

            iCalDateTime dt1    = new iCalDateTime(2003, 10, 26, 0, 59, 59, tz.TZID, iCal);
            iCalDateTime dt2    = new iCalDateTime(2003, 10, 26, 1, 0, 0, tz.TZID, iCal);
            TimeSpan     result = dt2 - dt1;

            Assert.AreEqual(TimeSpan.FromHours(1) + TimeSpan.FromSeconds(1), result);

            dt1    = new iCalDateTime(2004, 4, 4, 1, 59, 59, tz.TZID, iCal);
            dt2    = new iCalDateTime(2004, 4, 4, 2, 0, 0, tz.TZID, iCal);
            result = dt2 - dt1;
            Assert.AreEqual(TimeSpan.FromHours(-1) + TimeSpan.FromSeconds(1), result);
        }
예제 #13
0
        public void SystemTimeZone2()
        {
            System.TimeZoneInfo tzi = System.TimeZoneInfo.FindSystemTimeZoneById("Mountain Standard Time");
            Assert.IsNotNull(tzi);

            iCalendar iCal = new iCalendar();
            ITimeZone tz   = iCal.AddTimeZone(tzi, new DateTime(2000, 1, 1), false);

            Assert.IsNotNull(tz);

            iCalendarSerializer serializer = new iCalendarSerializer();

            serializer.Serialize(iCal, @"Calendars\Serialization\SystemTimeZone2.ics");

            // Ensure the time zone transition works as expected
            // (i.e. it takes 1 hour and 1 second to transition from
            // 2003-10-26 1:59:59 AM to
            // 2003-10-26 2:00:00 AM)
            iCalDateTime dt1    = new iCalDateTime(2003, 10, 26, 1, 59, 59, tz.TZID, iCal);
            iCalDateTime dt2    = new iCalDateTime(2003, 10, 26, 2, 0, 0, tz.TZID, iCal);
            TimeSpan     result = dt2 - dt1;

            Assert.AreEqual(TimeSpan.FromHours(1) + TimeSpan.FromSeconds(1), result);

            // Ensure another time zone transition works as expected
            // (i.e. it takes negative 59 minutes and 59 seconds to transition from
            // 2004-04-04 1:59:59 AM to
            // 2004-04-04 2:00:00 AM)
            dt1    = new iCalDateTime(2004, 4, 4, 1, 59, 59, tz.TZID, iCal);
            dt2    = new iCalDateTime(2004, 4, 4, 2, 0, 0, tz.TZID, iCal);
            result = dt2 - dt1;
            Assert.AreEqual(TimeSpan.FromHours(-1) + TimeSpan.FromSeconds(1), result);
        }
예제 #14
0
        private void EvaluateToPreviousOccurrence(iCalDateTime completedDate, iCalDateTime currDt)
        {
            iCalDateTime beginningDate = completedDate.Copy();

            if (RRule != null)
            {
                foreach (RecurrencePattern rrule in RRule)
                {
                    DetermineStartingRecurrence(rrule, ref beginningDate);
                }
            }
            if (RDate != null)
            {
                foreach (RecurrenceDates rdate in RDate)
                {
                    DetermineStartingRecurrence(rdate, ref beginningDate);
                }
            }
            if (ExRule != null)
            {
                foreach (RecurrencePattern exrule in ExRule)
                {
                    DetermineStartingRecurrence(exrule, ref beginningDate);
                }
            }
            if (ExDate != null)
            {
                foreach (RecurrenceDates exdate in ExDate)
                {
                    DetermineStartingRecurrence(exdate, ref beginningDate);
                }
            }

            Evaluate(beginningDate, currDt);
        }
예제 #15
0
        public override List <Period> Evaluate(iCalDateTime FromDate, iCalDateTime ToDate)
        {
            List <Period> periods = base.Evaluate(FromDate, ToDate);

            // Add the initial specified date/time for the time zone entry
            periods.Insert(0, new Period(Start, null));
            return(periods);
        }
예제 #16
0
        /// <summary>
        /// Polls <see cref="Alarm"/>s for occurrences within the <see cref="Evaluate"/>d
        /// time frame of this <see cref="RecurringComponent"/>.  For each evaluated
        /// occurrence if this component, each <see cref="Alarm"/> is polled for its
        /// corresponding alarm occurrences.
        /// <para>
        /// <example>
        /// The following is an example of polling alarms for an event.
        /// <code>
        /// iCalendar iCal = iCalendar.LoadFromUri(new Uri("http://somesite.com/calendar.ics"));
        /// Event evt = iCal.Events[0];
        ///
        /// // Poll the alarms on the event
        /// List<AlarmOccurrence> alarms = evt.PollAlarms();
        ///
        /// // Here, you would eliminate alarms that the user has already dismissed.
        /// // This information should be stored somewhere outside of the .ics file.
        /// // You can use the component's UID, and the AlarmOccurence date/time
        /// // as the primary key for each alarm occurrence.
        ///
        /// foreach(AlarmOccurrence alarm in alarms)
        ///     MessageBox.Show(alarm.Component.Summary + "\n" + alarm.DateTime);
        /// </code>
        /// </example>
        /// </para>
        /// </summary>
        /// <param name="Start">The earliest allowable alarm occurrence to poll, or <c>null</c>.</param>
        /// <returns>A List of <see cref="Alarm.AlarmOccurrence"/> objects, one for each occurrence of the <see cref="Alarm"/>.</returns>
        virtual public List <AlarmOccurrence> PollAlarms(iCalDateTime Start, iCalDateTime End)
        {
            List <AlarmOccurrence> Occurrences = new List <AlarmOccurrence>();

            foreach (Alarm alarm in Alarms)
            {
                Occurrences.AddRange(alarm.Poll(Start, End));
            }
            return(Occurrences);
        }
예제 #17
0
 private void DetermineStartingRecurrence(RecurrenceDates rdate, ref iCalDateTime dt)
 {
     foreach (Period p in rdate.Periods)
     {
         if (p.StartTime < dt)
         {
             dt = p.StartTime.Copy();
         }
     }
 }
        public iCalDateTimeInstance(ObjectInstance prototype, iCalDateTime iCalDateTime)
            : this(prototype)
        {
            if (iCalDateTime == null)
            {
                throw new ArgumentNullException("iCalDateTime");
            }

            m_iCalDateTime = iCalDateTime;
        }
예제 #19
0
 /// <summary>
 /// Use this method to determine if an event begins at a given date and time.
 /// </summary>
 /// <param name="DateTime">The date and time to test.</param>
 /// <returns>True if the event begins at the given date and time</returns>
 virtual public bool OccursAt(iCalDateTime DateTime)
 {
     foreach (Period p in Periods)
     {
         if (p.StartTime.Equals(DateTime))
         {
             return(true);
         }
     }
     return(false);
 }
예제 #20
0
        /// <summary>
        /// Gets a list of alarm occurrences for the given recurring component, <paramref name="rc"/>
        /// that occur between <paramref name="FromDate"/> and <paramref name="ToDate"/>.
        /// </summary>
        virtual public List <AlarmOccurrence> GetOccurrences(RecurringComponent rc, iCalDateTime FromDate, iCalDateTime ToDate)
        {
            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)
            {
                // Ensure that "FromDate" has already been set
                if (FromDate == null)
                {
                    FromDate = rc.Start.Copy();
                }

                Duration d = null;
                foreach (Occurrence o in rc.GetOccurrences(FromDate, ToDate))
                {
                    iCalDateTime dt = o.Period.StartTime;
                    if (Trigger.Related == Trigger.TriggerRelation.End)
                    {
                        if (o.Period.EndTime != null)
                        {
                            dt = o.Period.EndTime;
                            if (d == null)
                            {
                                d = o.Period.Duration;
                            }
                        }
                        // Use the "last-found" duration as a reference point
                        else if (d != null)
                        {
                            dt = o.Period.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);
        }
예제 #21
0
 private void DetermineStartingRecurrence(RecurrencePattern recur, ref iCalDateTime dt)
 {
     if (recur.Count != int.MinValue)
     {
         dt = DTStart.Copy();
     }
     else
     {
         recur.IncrementDate(ref dt, -recur.Interval);
     }
 }
예제 #22
0
        public iCalDateTimeUTCSerializer(iCalDateTime dt)
            : base(dt)
        {
            // Make a copy of the iCalDateTime object, so we don't alter
            // the original
            DateTime = dt.Copy();

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

            // Ensure time is serialized
            DateTime.HasTime = true;
        }
예제 #23
0
        public void TestAlarm(string calendar, List<IDateTime> dates, iCalDateTime start, iCalDateTime end)
        {
            IICalendar iCal = iCalendar.LoadFromFile(@"Calendars/Alarm/" + calendar)[0];
            ProgramTest.TestCal(iCal);
            IEvent evt = iCal.Events.First();
            
            // Poll all alarms that occurred between Start and End
            IList<AlarmOccurrence> alarms = evt.PollAlarms(start, end);

            foreach (AlarmOccurrence alarm in alarms)
                Assert.IsTrue(dates.Contains(alarm.DateTime), "Alarm triggers at " + alarm.Period.StartTime + ", but it should not.");
            Assert.IsTrue(dates.Count == alarms.Count, "There were " + alarms.Count + " alarm occurrences; there should have been " + dates.Count + ".");
        }
예제 #24
0
        public override System.Collections.Generic.List <Period> Evaluate(iCalDateTime FromDate, iCalDateTime ToDate)
        {
            if (Start != null)
            {
                Period p = new Period(Start);
                if (!Periods.Contains(p))
                {
                    Periods.Add(p);
                }

                return(base.Evaluate(FromDate, ToDate));
            }
            return(new System.Collections.Generic.List <Period>());
        }
예제 #25
0
        /// <summary>
        /// Polls the <see cref="Alarm"/> component for alarms that have been triggered
        /// since the provided <paramref name="Start"/> date/time.  If <paramref name="Start"/>
        /// is null, all triggered alarms will be returned.
        /// </summary>
        /// <param name="Start">The earliest date/time to poll trigerred alarms for.</param>
        /// <returns>A list of <see cref="AlarmOccurrence"/> objects, each containing a triggered alarm.</returns>
        public List <AlarmOccurrence> Poll(iCalDateTime Start, iCalDateTime End)
        {
            List <AlarmOccurrence> Results = new List <AlarmOccurrence>();

            // Evaluate the alarms to determine the recurrences
            RecurringComponent rc = Parent as RecurringComponent;

            if (rc != null)
            {
                Results.AddRange(GetOccurrences(rc, Start, End));
                Results.Sort();
            }
            return(Results);
        }
예제 #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>
 virtual public bool OccursOn(iCalDateTime 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 iCalDateTime(2006, 7, 5)); // Evals to true; should be false
             return true;
     return false;
 }
예제 #27
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(iCalDateTime currDt)
 {
     if (DTStart == null)
     {
         return(!IsCompleted(currDt) && !IsCancelled());
     }
     else if (currDt >= DTStart)
     {
         return(!IsCompleted(currDt) && !IsCancelled());
     }
     else
     {
         return(false);
     }
 }
예제 #28
0
        public void Bug3191956()
        {
            var queue = new Queue <iCalDateTime>();

            for (int i = 0; i < 4; i++)
            {
                var dateTime = new iCalDateTime(2011, 1, 1);
                dateTime.HasTime = false;
                queue.Enqueue(dateTime);
            }

            IDateTime dt = queue.Dequeue();

            Assert.IsFalse(dt.HasTime);
            dt = dt.AddHours(0);
            Assert.IsFalse(dt.HasTime);
            dt = dt.AddHours(24);
            Assert.IsFalse(dt.HasTime);
            dt = dt.AddHours(1);
            Assert.IsTrue(dt.HasTime);

            dt = queue.Dequeue();
            Assert.IsFalse(dt.HasTime);
            dt = dt.AddMinutes(0);
            Assert.IsFalse(dt.HasTime);
            dt = dt.AddMinutes(1440);
            Assert.IsFalse(dt.HasTime);
            dt = dt.AddMinutes(1);
            Assert.IsTrue(dt.HasTime);

            dt = queue.Dequeue();
            Assert.IsFalse(dt.HasTime);
            dt = dt.AddSeconds(0);
            Assert.IsFalse(dt.HasTime);
            dt = dt.AddSeconds(86400);
            Assert.IsFalse(dt.HasTime);
            dt = dt.AddSeconds(1);
            Assert.IsTrue(dt.HasTime);

            dt = queue.Dequeue();
            Assert.IsFalse(dt.HasTime);
            dt = dt.AddMilliseconds(0);
            Assert.IsFalse(dt.HasTime);
            dt = dt.AddMilliseconds(86400000);
            Assert.IsFalse(dt.HasTime);
            dt = dt.AddMilliseconds(1);
            Assert.IsTrue(dt.HasTime);
        }
예제 #29
0
        public void TestAlarm(string calendar, List <IDateTime> dates, iCalDateTime start, iCalDateTime end)
        {
            IICalendar iCal = iCalendar.LoadFromFile(@"Calendars\Alarm\" + calendar)[0];

            ProgramTest.TestCal(iCal);
            IEvent evt = iCal.Events[0];

            // Poll all alarms that occurred between Start and End
            IList <AlarmOccurrence> alarms = evt.PollAlarms(start, end);

            foreach (AlarmOccurrence alarm in alarms)
            {
                Assert.IsTrue(dates.Contains(alarm.DateTime), "Alarm triggers at " + alarm.Period.StartTime + ", but it should not.");
            }
            Assert.IsTrue(dates.Count == alarms.Count, "There were " + alarms.Count + " alarm occurrences; there should have been " + dates.Count + ".");
        }
예제 #30
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 iCalDateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second);
            DTStamp = Created.Copy();
        }
예제 #31
0
        /// <summary>
        /// Возвращает список событий как виртуальных так и реальных.
        /// </summary>
        /// <param name="filterColl">The filter coll.</param>
        /// <param name="request">The request.</param>
        /// <returns></returns>
        private static IEnumerable <CalendarEventEntity> ListEvents(FilterElementCollection filterColl, CalendarEventListRequest request)
        {
            McEvent mcEvent = null;
            //Конструируем стандартный запрос LIST без критериев содержащих дату начала и конца события
            ListRequest moListRequest = (ListRequest)EventHelper.ConstructRequest <ListRequest>(request.Target, true);

            moListRequest.Filters = filterColl.ToArray();
            moListRequest.Sorting = request.Sorting;
            //выполняем стандартный запрос
            ListResponse listResp = (ListResponse)BusinessManager.Execute(moListRequest);

            if (listResp != null && listResp.EntityObjects != null)
            {
                //Пробегаем по реальным events
                foreach (CalendarEventEntity entity in listResp.EntityObjects)
                {
                    mcEvent = EventHelper.LoadCalEvent(entity.PrimaryKeyId.Value);
                    if (mcEvent.IsReccuring)
                    {
                        iCalDateTime dtReccurBase = mcEvent.DTStart;
                        //Пробегаем по виртуальным events
                        foreach (Occurrence occur in mcEvent.GetOccurrences(mcEvent.DTStart, mcEvent.RecurrenceSeriesEndDate))
                        {
                            //Создаем виртуальные события
                            VirtualEventId vEventId = (VirtualEventId)entity.PrimaryKeyId;
                            vEventId.RecurrenceId = EventHelper.iCalDateTime2Recurrence(dtReccurBase, occur.Period.StartTime);
                            //Set virtual id
                            mcEvent.UID = vEventId.ToString();
                            //Set recurrence-ID
                            mcEvent.Recurrence_ID = occur.Period.StartTime;
                            mcEvent.DTStart       = occur.Period.StartTime;
                            mcEvent.DTEnd         = occur.Period.EndTime;
                            EntityObjectHierarchy recurrenceEntity = EventHelper.ConstructEntityHierarchy(mcEvent);
                            CalendarEventEntity   occurEventEntity = recurrenceEntity.InnerEntity as CalendarEventEntity;
                            if (occurEventEntity != null)
                            {
                                yield return(occurEventEntity);
                            }
                        }
                    }
                    else
                    {
                        yield return(entity);
                    }
                }
            }
        }
예제 #32
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(iCalDateTime startTime, iCalDateTime 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);
        }
예제 #33
0
        public void iCalSingleEventIsFuture()
        {
            var ics        = basic_ics;
            var futuredate = DateTime.Now + new TimeSpan(10, 0, 0, 0, 0);

            ics = ics.Replace("__SINGLE_DATE_START__", futuredate.ToString("yyyyMMdd"));
            ics = ics.Replace("__SINGLE_DATE_END__", futuredate.ToString("yyyyMMdd"));
            StringReader sr       = new StringReader(ics);
            var          ical     = iCalendar.LoadFromStream(sr).First().Calendar;
            var          evt      = ical.Events[0];
            var          ical_now = new iCalDateTime(DateTime.Now.ToUniversalTime());

            Assert.That(evt.GetOccurrences(ical_now).Count == 0);
            var collector = new Collector(test_calinfo, settings);

            Assert.IsTrue(Collector.IsCurrentOrFutureDTStartInTz(evt.Start.Date, test_calinfo.tzinfo));
        }
        public void Bug3191956()
        {
            var queue = new Queue<iCalDateTime>();
            for (int i = 0; i < 4; i++)
            {
                var dateTime = new iCalDateTime(2011, 1, 1);
                dateTime.HasTime = false;
                queue.Enqueue(dateTime);
            }

            IDateTime dt = queue.Dequeue();
            Assert.IsFalse(dt.HasTime);
            dt = dt.AddHours(0);
            Assert.IsFalse(dt.HasTime);
            dt = dt.AddHours(24);
            Assert.IsFalse(dt.HasTime);
            dt = dt.AddHours(1);
            Assert.IsTrue(dt.HasTime);

            dt = queue.Dequeue();
            Assert.IsFalse(dt.HasTime);
            dt = dt.AddMinutes(0);
            Assert.IsFalse(dt.HasTime);
            dt = dt.AddMinutes(1440);
            Assert.IsFalse(dt.HasTime);
            dt = dt.AddMinutes(1);
            Assert.IsTrue(dt.HasTime);

            dt = queue.Dequeue();
            Assert.IsFalse(dt.HasTime);
            dt = dt.AddSeconds(0);
            Assert.IsFalse(dt.HasTime);
            dt = dt.AddSeconds(86400);
            Assert.IsFalse(dt.HasTime);
            dt = dt.AddSeconds(1);
            Assert.IsTrue(dt.HasTime);

            dt = queue.Dequeue();
            Assert.IsFalse(dt.HasTime);
            dt = dt.AddMilliseconds(0);
            Assert.IsFalse(dt.HasTime);
            dt = dt.AddMilliseconds(86400000);
            Assert.IsFalse(dt.HasTime);
            dt = dt.AddMilliseconds(1);
            Assert.IsTrue(dt.HasTime);
        }
예제 #35
0
        public void RecurrencePattern2()
        {
            // NOTE: evaluators are generally not meant to be used directly like this.
            // However, this does make a good test to ensure they behave as they should.
            RecurrencePattern pattern = new RecurrencePattern("FREQ=MINUTELY;INTERVAL=1");

            CultureInfo us = CultureInfo.CreateSpecificCulture("en-US");

            iCalDateTime startDate = new iCalDateTime(DateTime.Parse("3/31/2008 12:00:10 AM", us));
            iCalDateTime fromDate = new iCalDateTime(DateTime.Parse("4/1/2008 10:08:10 AM", us));
            iCalDateTime toDate = new iCalDateTime(DateTime.Parse("4/1/2008 10:43:23 AM", us));

            IEvaluator evaluator = pattern.GetService(typeof(IEvaluator)) as IEvaluator;
            Assert.IsNotNull(evaluator);

            IList<IPeriod> occurrences = evaluator.Evaluate(
                startDate, 
                DateUtil.SimpleDateTimeToMatch(fromDate, startDate), 
                DateUtil.SimpleDateTimeToMatch(toDate, startDate),
                false);
            Assert.AreNotEqual(0, occurrences.Count);
        }
예제 #36
0
        public void RecurrencePattern1()
        {
            // NOTE: evaluators are not generally meant to be used directly like this.
            // However, this does make a good test to ensure they behave as they should.
            IRecurrencePattern pattern = new RecurrencePattern("FREQ=SECONDLY;INTERVAL=10");
            pattern.RestrictionType = RecurrenceRestrictionType.NoRestriction;

            CultureInfo us = CultureInfo.CreateSpecificCulture("en-US");

            iCalDateTime startDate = new iCalDateTime(DateTime.Parse("3/30/08 11:59:40 PM", us));
            iCalDateTime fromDate = new iCalDateTime(DateTime.Parse("3/30/08 11:59:40 PM", us));
            iCalDateTime toDate = new iCalDateTime(DateTime.Parse("3/31/08 12:00:11 AM", us));

            IEvaluator evaluator = pattern.GetService(typeof(IEvaluator)) as IEvaluator;
            Assert.IsNotNull(evaluator);

            IList<IPeriod> occurrences = evaluator.Evaluate(
                startDate, 
                DateUtil.SimpleDateTimeToMatch(fromDate, startDate), 
                DateUtil.SimpleDateTimeToMatch(toDate, startDate),
                false);
            Assert.AreEqual(4, occurrences.Count);
            Assert.AreEqual(new iCalDateTime(DateTime.Parse("03/30/08 11:59:40 PM", us)), occurrences[0].StartTime);
            Assert.AreEqual(new iCalDateTime(DateTime.Parse("03/30/08 11:59:50 PM", us)), occurrences[1].StartTime);
            Assert.AreEqual(new iCalDateTime(DateTime.Parse("03/31/08 12:00:00 AM", us)), occurrences[2].StartTime);
            Assert.AreEqual(new iCalDateTime(DateTime.Parse("03/31/08 12:00:10 AM", us)), occurrences[3].StartTime);
        }
예제 #37
0
        public void RECURPARSE6()
        {
            iCalendar iCal = new iCalendar();

            Event evt = iCal.Create<Event>();
            evt.Summary = "Test event";
            evt.Start = new iCalDateTime(2006, 1, 1, 9, 0, 0);
            evt.Duration = new TimeSpan(1, 0, 0);
            evt.RecurrenceRules.Add(new RecurrencePattern("Every month on the first sunday, at 5:00PM, and at 7:00PM"));

            IList<Occurrence> occurrences = evt.GetOccurrences(
                new iCalDateTime(2006, 1, 1),
                new iCalDateTime(2006, 3, 31));

            iCalDateTime[] DateTimes = new iCalDateTime[]
            {
                new iCalDateTime(2006, 1, 1, 9, 0, 0),
                new iCalDateTime(2006, 1, 1, 17, 0, 0),
                new iCalDateTime(2006, 1, 1, 19, 0, 0),
                new iCalDateTime(2006, 2, 5, 17, 0, 0),
                new iCalDateTime(2006, 2, 5, 19, 0, 0),
                new iCalDateTime(2006, 3, 5, 17, 0, 0),
                new iCalDateTime(2006, 3, 5, 19, 0, 0)
            };

            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);
        }
        public void Google1()
        {
            string tzid = "Europe/Berlin";
            IICalendar iCal = iCalendar.LoadFromFile(@"Calendars/Serialization/Google1.ics")[0];
            IEvent evt = iCal.Events["*****@*****.**"];
            Assert.IsNotNull(evt);

            IDateTime dtStart = new iCalDateTime(2006, 12, 18, tzid);
            IDateTime dtEnd = new iCalDateTime(2006, 12, 23, tzid);
            IList<Occurrence> occurrences = iCal.GetOccurrences(dtStart, dtEnd);

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

            for (int i = 0; i < DateTimes.Length; i++)
                Assert.AreEqual(DateTimes[i], occurrences[i].Period.StartTime, "Event should occur at " + DateTimes[i]);

            Assert.AreEqual(DateTimes.Length, occurrences.Count, "There should be exactly " + DateTimes.Length + " occurrences; there were " + occurrences.Count);
        }
예제 #39
0
파일: McEvent.cs 프로젝트: 0anion0/IBN
        /// <summary>
        /// Gets the occurrences.
        /// </summary>
        /// <param name="startTime">The start time.</param>
        /// <param name="endTime">The end time.</param>
        /// <remarks> Вычисляет все экземпляры рекурсивного события в соотв с паттерном рекурсии. С учетом exception event.
        /// </remarks>
        /// <returns></returns>
        public override List<Occurrence> GetOccurrences(iCalDateTime startTime, iCalDateTime endTime)
        {
            //Очищаем кеш повторений
            ClearEvaluation();

            List<Occurrence> retVal = base.GetOccurrences(startTime, endTime);

            if(RecurrenceException != null)
            {
                foreach (McEvent exception in RecurrenceException)
                {
                    if (exception.Recurrence_ID != null)
                    {
                        //Start = RecurrenceId, Duration = Parent event duration
                        Occurrence exceptionOccur = new Occurrence(null, new Period(exception.Recurrence_ID, this.Duration));
                        //remove exception from orig occurrences list
                        if (retVal.Contains(exceptionOccur))
                        {
                            retVal.Remove(exceptionOccur);
                        }
                    }
                }
            }
            return retVal;
        }
예제 #40
0
        public void Bug3312619()
        {
            IICalendar calendar = iCalendar.LoadFromFile(@"Calendars/Recurrence/Bug3312619.ics").First();
            iCalDateTime from = new iCalDateTime(2011, 6, 1) { HasTime = true };
            iCalDateTime to = new iCalDateTime(2012, 7, 1) { HasTime = true };

            var occurrences = calendar.GetOccurrences(from, to);
            Assert.AreEqual(59, occurrences.Count);
        }
예제 #41
0
        public void Test4()
        {
            IRecurrencePattern rpattern = new RecurrencePattern();
            rpattern.ByDay.Add(new WeekDay(DayOfWeek.Saturday));
            rpattern.ByDay.Add(new WeekDay(DayOfWeek.Sunday));

            rpattern.Frequency = FrequencyType.Weekly;

            IDateTime evtStart = new iCalDateTime(2006, 12, 1);
            IDateTime evtEnd = new iCalDateTime(2007, 1, 1);

            IEvaluator evaluator = rpattern.GetService(typeof(IEvaluator)) as IEvaluator;
            Assert.IsNotNull(evaluator);

            // Add the exception dates
            IList<IPeriod> periods = evaluator.Evaluate(
                evtStart,
                DateUtil.GetSimpleDateTimeData(evtStart), 
                DateUtil.SimpleDateTimeToMatch(evtEnd, evtStart),
                false);
            Assert.AreEqual(10, periods.Count);
            Assert.AreEqual(2, periods[0].StartTime.Day);
            Assert.AreEqual(3, periods[1].StartTime.Day);
            Assert.AreEqual(9, periods[2].StartTime.Day);
            Assert.AreEqual(10, periods[3].StartTime.Day);
            Assert.AreEqual(16, periods[4].StartTime.Day);
            Assert.AreEqual(17, periods[5].StartTime.Day);
            Assert.AreEqual(23, periods[6].StartTime.Day);
            Assert.AreEqual(24, periods[7].StartTime.Day);
            Assert.AreEqual(30, periods[8].StartTime.Day);
            Assert.AreEqual(31, periods[9].StartTime.Day);
        }
예제 #42
0
        public void SystemTimeZone1()
        {
//            System.TimeZoneInfo tzi = System.TimeZoneInfo.FindSystemTimeZoneById("Mountain Standard Time");
            System.TimeZoneInfo tzi = System.TimeZoneInfo.FindSystemTimeZoneById("America/Denver");
            Assert.IsNotNull(tzi);

            iCalendar iCal = new iCalendar();
            ITimeZone tz = iCal.AddTimeZone(tzi, new DateTime(2000, 1, 1), false);

            iCalendarSerializer serializer = new iCalendarSerializer();
            serializer.Serialize(iCal, @"Calendars/Serialization/SystemTimeZone1.ics");

            // Ensure the time zone transition works as expected
            // (i.e. it takes 1 hour and 1 second to transition from
            // 2003-10-26 1:59:59 AM to
            // 2003-10-26 2:00:00 AM)
            iCalDateTime dt1 = new iCalDateTime(2003, 10, 26, 1, 59, 59, tz.TZID, iCal);
            iCalDateTime dt2 = new iCalDateTime(2003, 10, 26, 2, 0, 0, tz.TZID, iCal);

            TimeSpan result = dt2 - dt1;
            Assert.AreEqual(TimeSpan.FromHours(1) + TimeSpan.FromSeconds(1), result);

            // Ensure another time zone transition works as expected
            // (i.e. it takes negative 59 minutes and 59 seconds to transition from
            // 2004-04-04 01:59:59 AM to
            // 2004-04-04 02:00:00 AM)
            
            // NOTE: We have a negative difference between the two values
            // because we 'spring ahead', and an hour is lost.
            dt1 = new iCalDateTime(2004, 4, 4, 1, 59, 59, tz.TZID, iCal);
            dt2 = new iCalDateTime(2004, 4, 4, 2, 0, 0, tz.TZID, iCal);
            result = dt2 - dt1;
            Assert.AreEqual(TimeSpan.FromHours(-1) + TimeSpan.FromSeconds(1), result);            
        }
예제 #43
0
        public void SystemTimeZone2()
        {
            System.TimeZoneInfo tzi = System.TimeZoneInfo.FindSystemTimeZoneById("Mountain Standard Time");
            Assert.IsNotNull(tzi);

            iCalendar iCal = new iCalendar();
            ITimeZone tz = iCal.AddTimeZone(tzi);
            Assert.IsNotNull(tz);

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

            iCalDateTime dt1 = new iCalDateTime(2003, 10, 26, 0, 59, 59, tz.TZID, iCal);
            iCalDateTime dt2 = new iCalDateTime(2003, 10, 26, 1, 0, 0, tz.TZID, iCal);
            TimeSpan result = dt2 - dt1;
            Assert.AreEqual(TimeSpan.FromHours(1) + TimeSpan.FromSeconds(1), result);

            dt1 = new iCalDateTime(2004, 4, 4, 1, 59, 59, tz.TZID, iCal);
            dt2 = new iCalDateTime(2004, 4, 4, 2, 0, 0, tz.TZID, iCal);
            result = dt2 - dt1;
            Assert.AreEqual(TimeSpan.FromHours(-1) + TimeSpan.FromSeconds(1), result);
        }
예제 #44
0
        public void Merge1()
        {
            IICalendar iCal1 = iCalendar.LoadFromFile(@"Calendars\Recurrence\MonthlyCountByMonthDay3.ics")[0];
            IICalendar iCal2 = iCalendar.LoadFromFile(@"Calendars\Recurrence\MonthlyByDay1.ics")[0];

            // Change the UID of the 2nd event to make sure it's different
            iCal2.Events[iCal1.Events[0].UID].UID = "1234567890";
            iCal1.MergeWith(iCal2);

            IEvent evt1 = iCal1.Events[0];
            IEvent evt2 = iCal1.Events[1];

            // Get occurrences for the first event
            IList<Occurrence> occurrences = evt1.GetOccurrences(
                new iCalDateTime(1996, 1, 1, tzid),
                new iCalDateTime(2000, 1, 1, tzid));

            iCalDateTime[] DateTimes = new iCalDateTime[]
            {
                new iCalDateTime(1997, 9, 10, 9, 0, 0, tzid),
                new iCalDateTime(1997, 9, 11, 9, 0, 0, tzid),
                new iCalDateTime(1997, 9, 12, 9, 0, 0, tzid),
                new iCalDateTime(1997, 9, 13, 9, 0, 0, tzid),
                new iCalDateTime(1997, 9, 14, 9, 0, 0, tzid),
                new iCalDateTime(1997, 9, 15, 9, 0, 0, tzid),
                new iCalDateTime(1999, 3, 10, 9, 0, 0, tzid),
                new iCalDateTime(1999, 3, 11, 9, 0, 0, tzid),
                new iCalDateTime(1999, 3, 12, 9, 0, 0, tzid),
                new iCalDateTime(1999, 3, 13, 9, 0, 0, tzid),
            };

            string[] TimeZones = new string[]
            {
                "EDT",
                "EDT",
                "EDT",
                "EDT",
                "EDT",
                "EDT",
                "EST",
                "EST",
                "EST",
                "EST"                
            };

            for (int i = 0; i < DateTimes.Length; i++)
            {
                IDateTime dt = DateTimes[i];
                IDateTime start = occurrences[i].Period.StartTime;
                Assert.AreEqual(dt, start);
                Assert.IsTrue(dt.TimeZoneName == TimeZones[i], "Event " + dt + " should occur in the " + TimeZones[i] + " timezone");
            }

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

            // Get occurrences for the 2nd event
            occurrences = evt2.GetOccurrences(
                new iCalDateTime(1996, 1, 1, tzid),
                new iCalDateTime(1998, 4, 1, tzid));

            iCalDateTime[] DateTimes1 = new iCalDateTime[]
            {
                new iCalDateTime(1997, 9, 2, 9, 0, 0, tzid),
                new iCalDateTime(1997, 9, 9, 9, 0, 0, tzid),
                new iCalDateTime(1997, 9, 16, 9, 0, 0, tzid),
                new iCalDateTime(1997, 9, 23, 9, 0, 0, tzid),
                new iCalDateTime(1997, 9, 30, 9, 0, 0, tzid),
                new iCalDateTime(1997, 11, 4, 9, 0, 0, tzid),
                new iCalDateTime(1997, 11, 11, 9, 0, 0, tzid),
                new iCalDateTime(1997, 11, 18, 9, 0, 0, tzid),
                new iCalDateTime(1997, 11, 25, 9, 0, 0, tzid),
                new iCalDateTime(1998, 1, 6, 9, 0, 0, tzid),
                new iCalDateTime(1998, 1, 13, 9, 0, 0, tzid),
                new iCalDateTime(1998, 1, 20, 9, 0, 0, tzid),
                new iCalDateTime(1998, 1, 27, 9, 0, 0, tzid),
                new iCalDateTime(1998, 3, 3, 9, 0, 0, tzid),
                new iCalDateTime(1998, 3, 10, 9, 0, 0, tzid),
                new iCalDateTime(1998, 3, 17, 9, 0, 0, tzid),
                new iCalDateTime(1998, 3, 24, 9, 0, 0, tzid),
                new iCalDateTime(1998, 3, 31, 9, 0, 0, tzid)
            };

            string[] TimeZones1 = new string[]
            {
                "EDT",
                "EDT",
                "EDT",
                "EDT",                
                "EDT",
                "EST",
                "EST",
                "EST",
                "EST",
                "EST",
                "EST",
                "EST",
                "EST",
                "EST",
                "EST",
                "EST",
                "EST",
                "EST"                
            };

            for (int i = 0; i < DateTimes1.Length; i++)
            {
                IDateTime dt = DateTimes1[i];
                IDateTime start = occurrences[i].Period.StartTime;
                Assert.AreEqual(dt, start);
                Assert.IsTrue(dt.TimeZoneName == TimeZones1[i], "Event " + dt + " should occur in the " + TimeZones1[i] + " timezone");
            }

            Assert.AreEqual(DateTimes1.Length, occurrences.Count, "There should be exactly " + DateTimes1.Length + " occurrences; there were " + occurrences.Count);
        }
예제 #45
0
        public void SystemTimeZone2()
        {
            System.TimeZoneInfo tzi = System.TimeZoneInfo.FindSystemTimeZoneById("Mountain Standard Time");
            Assert.IsNotNull(tzi);

            iCalendar iCal = new iCalendar();
            ITimeZone tz = iCal.AddTimeZone(tzi, new DateTime(2000, 1, 1), false);
            Assert.IsNotNull(tz);

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

            // Ensure the time zone transition works as expected
            // (i.e. it takes 1 hour and 1 second to transition from
            // 2003-10-26 12:59:59 AM to
            // 2003-10-26 01:00:00 AM)
            iCalDateTime dt1 = new iCalDateTime(2003, 10, 26, 0, 59, 59, tz.TZID, iCal);
            iCalDateTime dt2 = new iCalDateTime(2003, 10, 26, 1, 0, 0, tz.TZID, iCal);
            TimeSpan result = dt2 - dt1;
            Assert.AreEqual(TimeSpan.FromHours(1) + TimeSpan.FromSeconds(1), result);

            // Ensure another time zone transition works as expected
            // (i.e. it takes negative 59 minutes and 59 seconds to transition from
            // 2004-04-04 01:59:59 AM to
            // 2004-04-04 02:00:00 AM)
            dt1 = new iCalDateTime(2004, 4, 4, 1, 59, 59, tz.TZID, iCal);
            dt2 = new iCalDateTime(2004, 4, 4, 2, 0, 0, tz.TZID, iCal);
            result = dt2 - dt1;
            Assert.AreEqual(TimeSpan.FromHours(-1) + TimeSpan.FromSeconds(1), result);
        }
예제 #46
0
        public void Bug3312617()
        {
            IICalendar calendar = iCalendar.LoadFromFile(@"Calendars/Recurrence/Bug3312617.ics").First();
            iCalDateTime from = new iCalDateTime(2013, 1, 1, true);
            iCalDateTime to = new iCalDateTime(2015, 12, 31, true);

            var occurrences = calendar.GetOccurrences(from, to);
            var daysDifference = to.Subtract(from).Days;
            Assert.AreEqual(daysDifference, occurrences.Count);
        }
예제 #47
0
        public void GetOccurrences1()
        {
            IICalendar iCal = new iCalendar();
            IEvent evt = iCal.Create<Event>();
            evt.Start = new iCalDateTime(2009, 11, 18, 5, 0, 0);
            evt.End = new iCalDateTime(2009, 11, 18, 5, 10, 0);
            evt.RecurrenceRules.Add(new RecurrencePattern(FrequencyType.Daily));
            evt.Summary = "xxxxxxxxxxxxx";
 
            iCalDateTime previousDateAndTime = new iCalDateTime(2009, 11, 17, 0, 15, 0);
            iCalDateTime previousDateOnly = new iCalDateTime(2009, 11, 17, 23, 15, 0);
            iCalDateTime laterDateOnly = new iCalDateTime(2009, 11, 19, 3, 15, 0);
            iCalDateTime laterDateAndTime = new iCalDateTime(2009, 11, 19, 11, 0, 0);
            iCalDateTime end = new iCalDateTime(2009, 11, 23, 0, 0, 0);

            IList<Occurrence> occurrences = null;

            occurrences = evt.GetOccurrences(previousDateAndTime, end);
            Assert.AreEqual(5, occurrences.Count);

            occurrences = evt.GetOccurrences(previousDateOnly, end);
            Assert.AreEqual(5, occurrences.Count);

            occurrences = evt.GetOccurrences(laterDateOnly, end);
            Assert.AreEqual(4, occurrences.Count);

            occurrences = evt.GetOccurrences(laterDateAndTime, end);
            Assert.AreEqual(3, occurrences.Count);

            // Add ByHour "9" and "12"            
            evt.RecurrenceRules[0].ByHour.Add(9);
            evt.RecurrenceRules[0].ByHour.Add(12);

            // Clear the evaluation so we can calculate recurrences again.
            evt.ClearEvaluation();

            occurrences = evt.GetOccurrences(previousDateAndTime, end);
            Assert.AreEqual(11, occurrences.Count);

            occurrences = evt.GetOccurrences(previousDateOnly, end);
            Assert.AreEqual(11, occurrences.Count);

            occurrences = evt.GetOccurrences(laterDateOnly, end);
            Assert.AreEqual(8, occurrences.Count);

            occurrences = evt.GetOccurrences(laterDateAndTime, end);
            Assert.AreEqual(7, occurrences.Count);
        }
예제 #48
0
        public void DailyUntil1()
        {
            IICalendar iCal = iCalendar.LoadFromFile(@"Calendars\Recurrence\DailyUntil1.ics")[0];
            ProgramTest.TestCal(iCal);
            IEvent evt = iCal.Events[0];

            IList<Occurrence> occurrences = evt.GetOccurrences(
                new iCalDateTime(1997, 9, 1, tzid),
                new iCalDateTime(1998, 1, 1, tzid));

            IDateTime dt = new iCalDateTime(1997, 9, 2, 9, 0, 0, tzid);
            int i = 0;
            while (dt.Year < 1998)
            {
                if ((dt.GreaterThanOrEqual(evt.Start)) &&
                    (dt.LessThan(new iCalDateTime(1997, 12, 24, 0, 0, 0, tzid))))
                {
                    Assert.AreEqual(dt, occurrences[i].Period.StartTime, "Event should occur at " + dt);
                    Assert.IsTrue(
                        (dt.LessThan(new iCalDateTime(1997, 10, 26, tzid)) && dt.TimeZoneName == "EDT") ||
                        (dt.GreaterThan(new iCalDateTime(1997, 10, 26, tzid)) && dt.TimeZoneName == "EST"),
                        "Event " + dt + " doesn't occur in the correct time zone (including Daylight & Standard time zones)");
                    i++;
                }

                dt = dt.AddDays(1);
            }
        }
예제 #49
0
        public void Test3()
        {
            IICalendar iCal = new iCalendar();
            IEvent evt = iCal.Create<Event>();

            evt.Start = new iCalDateTime(2008, 10, 18, 10, 30, 0);
            evt.Summary = "Test Event";
            evt.Duration = TimeSpan.FromHours(1);
            evt.RecurrenceRules.Add(new RecurrencePattern("RRULE:FREQ=WEEKLY;BYDAY=MO,TU,WE,TH"));

            IDateTime doomsdayDate = new iCalDateTime(2010, 12, 31, 10, 30, 0);
            IList<Occurrence> allOcc = evt.GetOccurrences(evt.Start, doomsdayDate);

            foreach (Occurrence occ in allOcc)
                Console.WriteLine(occ.Period.StartTime.ToString("d") + " " + occ.Period.StartTime.ToString("t"));
        }
예제 #50
0
        public void USHolidays()
        {
            IICalendar iCal = iCalendar.LoadFromFile(@"Calendars\Serialization\USHolidays.ics")[0];

            Assert.IsNotNull(iCal, "iCalendar was not loaded.");
            Hashtable items = new Hashtable();
            items["Christmas"] = new iCalDateTime(2006, 12, 25);
            items["Thanksgiving"] = new iCalDateTime(2006, 11, 23);
            items["Veteran's Day"] = new iCalDateTime(2006, 11, 11);
            items["Halloween"] = new iCalDateTime(2006, 10, 31);
            items["Daylight Saving Time Ends"] = new iCalDateTime(2006, 10, 29);
            items["Columbus Day"] = new iCalDateTime(2006, 10, 9);
            items["Labor Day"] = new iCalDateTime(2006, 9, 4);
            items["Independence Day"] = new iCalDateTime(2006, 7, 4);
            items["Father's Day"] = new iCalDateTime(2006, 6, 18);
            items["Flag Day"] = new iCalDateTime(2006, 6, 14);
            items["John F. Kennedy's Birthday"] = new iCalDateTime(2006, 5, 29);
            items["Memorial Day"] = new iCalDateTime(2006, 5, 29);
            items["Mother's Day"] = new iCalDateTime(2006, 5, 14);
            items["Cinco de Mayo"] = new iCalDateTime(2006, 5, 5);
            items["Earth Day"] = new iCalDateTime(2006, 4, 22);
            items["Easter"] = new iCalDateTime(2006, 4, 16);
            items["Tax Day"] = new iCalDateTime(2006, 4, 15);
            items["Daylight Saving Time Begins"] = new iCalDateTime(2006, 4, 2);
            items["April Fool's Day"] = new iCalDateTime(2006, 4, 1);
            items["St. Patrick's Day"] = new iCalDateTime(2006, 3, 17);
            items["Washington's Birthday"] = new iCalDateTime(2006, 2, 22);
            items["President's Day"] = new iCalDateTime(2006, 2, 20);
            items["Valentine's Day"] = new iCalDateTime(2006, 2, 14);
            items["Lincoln's Birthday"] = new iCalDateTime(2006, 2, 12);
            items["Groundhog Day"] = new iCalDateTime(2006, 2, 2);
            items["Martin Luther King, Jr. Day"] = new iCalDateTime(2006, 1, 16);
            items["New Year's Day"] = new iCalDateTime(2006, 1, 1);

            IList<Occurrence> occurrences = iCal.GetOccurrences(
                new iCalDateTime(2006, 1, 1),
                new iCalDateTime(2006, 12, 31));

            Assert.AreEqual(items.Count, occurrences.Count, "The number of holidays did not evaluate correctly.");
            foreach (Occurrence o in occurrences)
            {
                IEvent evt = o.Source as IEvent;
                Assert.IsNotNull(evt);
                Assert.IsTrue(items.ContainsKey(evt.Summary), "Holiday text '" + evt.Summary + "' did not match known holidays.");
                Assert.AreEqual(items[evt.Summary], o.Period.StartTime, "Date/time of holiday '" + evt.Summary + "' did not match.");
            }
        }
예제 #51
0
        public void ByMonth1()
        {
            IICalendar iCal = iCalendar.LoadFromFile(@"Calendars\Recurrence\ByMonth1.ics")[0];
            ProgramTest.TestCal(iCal);
            IEvent evt = iCal.Events[0];

            IList<Occurrence> occurrences = evt.GetOccurrences(
                new iCalDateTime(1998, 1, 1, tzid),
                new iCalDateTime(2000, 12, 31, tzid));

            IDateTime dt = new iCalDateTime(1998, 1, 1, 9, 0, 0, tzid);
            int i = 0;
            while (dt.Year < 2001)
            {
                if (dt.GreaterThanOrEqual(evt.Start) &&
                    dt.Month == 1 &&
                    dt.LessThanOrEqual(new iCalDateTime(2000, 1, 31, 9, 0, 0, tzid)))
                {
                    Assert.AreEqual(dt, occurrences[i].Period.StartTime, "Event should occur at " + dt);
                    i++;
                }

                dt = dt.AddDays(1);
            }
        }
예제 #52
0
        public void RECURPARSE1()
        {
            iCalendar iCal = new iCalendar();

            Event evt = iCal.Create<Event>();
            evt.Summary = "Test event";
            evt.Start = new iCalDateTime(2006, 10, 1, 9, 0, 0);
            evt.Duration = new TimeSpan(1, 0, 0);
            evt.RecurrenceRules.Add(new RecurrencePattern("Every 3rd month on the last tuesday and wednesday"));

            IList<Occurrence> occurrences = evt.GetOccurrences(
                new iCalDateTime(2006, 10, 1),
                new iCalDateTime(2007, 4, 30));

            iCalDateTime[] DateTimes = new iCalDateTime[]
            {
                new iCalDateTime(2006, 10, 1, 9, 0, 0),
                new iCalDateTime(2006, 10, 25, 9, 0, 0),
                new iCalDateTime(2006, 10, 31, 9, 0, 0),
                new iCalDateTime(2007, 1, 30, 9, 0, 0),
                new iCalDateTime(2007, 1, 31, 9, 0, 0),
                new iCalDateTime(2007, 4, 24, 9, 0, 0),
                new iCalDateTime(2007, 4, 25, 9, 0, 0)
            };

            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);
        }
예제 #53
0
        public void Bug3312618and3522651()
        {
            IICalendar calendar = iCalendar.LoadFromFile(@"Calendars/Recurrence/Bug3312618and3522651.ics").First();
            iCalDateTime from = new iCalDateTime(2010, 1, 1, true);
            iCalDateTime to = new iCalDateTime(2011, 12, 31, true);

            var occurrences = calendar.GetOccurrences(from, to);
            Assert.AreEqual(1, occurrences.Count);
            Assert.AreEqual(0, occurrences[0].Period.Duration.Ticks);
        }
예제 #54
0
        public void RECURPARSE5()
        {
            iCalendar iCal = new iCalendar();

            Event evt = iCal.Create<Event>();
            evt.Summary = "Test event";
            evt.Start = new iCalDateTime(2006, 1, 1, 9, 0, 0);
            evt.Duration = new TimeSpan(1, 0, 0);
            evt.RecurrenceRules.Add(new RecurrencePattern("Every 10 minutes until 1/1/2006 9:50"));

            IList<Occurrence> occurrences = evt.GetOccurrences(
                new iCalDateTime(2006, 1, 1),
                new iCalDateTime(2006, 1, 31));

            iCalDateTime[] DateTimes = new iCalDateTime[]
            {
                new iCalDateTime(2006, 1, 1, 9, 0, 0),
                new iCalDateTime(2006, 1, 1, 9, 10, 0),
                new iCalDateTime(2006, 1, 1, 9, 20, 0),
                new iCalDateTime(2006, 1, 1, 9, 30, 0),
                new iCalDateTime(2006, 1, 1, 9, 40, 0),
                new iCalDateTime(2006, 1, 1, 9, 50, 0)
            };

            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);
        }
예제 #55
0
파일: McEvent.cs 프로젝트: 0anion0/IBN
 /// <summary>
 /// Counts to until replace. For  recurrence pattern
 /// </summary>
 /// <param name="dtStart">The dt start.</param>
 /// <param name="until">The until.</param>
 /// <param name="rpattern">The rpattern.</param>
 private static void CountToUntilReplace(iCalDateTime dtStart, iCalDateTime until, RecurrencePattern pattern)
 {
     //COUNT is specified
     if (pattern.Count > 0)
     {
         List<iCalDateTime> occurs = pattern.Evaluate(dtStart, dtStart, until);
         if (occurs.Count != 0 && occurs[occurs.Count - 1] >= until)
         {
             //Remove COUNT
             pattern.Count = int.MinValue;
             pattern.Until = until;
         }
     }
     else
     {
         pattern.Until = until;
     }
 }
 public void Bug3354307()
 {
     var now = DateTime.Now;
     var dt = new iCalDateTime(now);
     Assert.AreEqual(dt, (object)now);
 }