public void Occurrences_before_start()
 {
     // 20/4, 23/4, 26/4, 29/4, 2/5, 5/5, 8/5
     DailySchedule day = new DailySchedule { Frequency = 3 };
     IList<DateTime> occurrences = Convert(day.GetOccurrences(_start, new DateTime(2010, 4, 1), new DateTime(2010, 4, 10)));
     
     Assert.AreEqual(0, occurrences.Count);
 }
        public void Next_occurrence_before_start()
        {
            // 20/4, 23/4, 26/4, 29/4, 2/5, 5/5, 8/5
            DailySchedule day = new DailySchedule { Frequency = 3 };
            DateTime? next = day.NextOccurrence(_start, new DateTime(2010, 1, 1));

            Assert.IsTrue(next.HasValue);
            Assert.AreEqual(_start, next.Value);
        }
 /// <summary>
 /// Gets the generated description for the schedule.  Will not update Description or fire events.
 /// </summary>
 public virtual string Format(DailySchedule s)
 {
     // Daily
     // Every 2 days
      return String.Format(
             Strings.Plural(s.Frequency, "Daily", "Every {0} days"),
             s.Frequency
         );
 }
        public void Occurrences_stress_test()
        {
            DailySchedule day = new DailySchedule { Frequency = 1 };
            var d = new DateTime(1990, 1, 1);

            // 1/1/1990 -> 1/1/2010 = 365 * 20 + 5 extra days due to leap years (1992, 1996, 2000, 2004, 2008)
            IList<DateTime> occurrences = Convert(day.GetOccurrences(d, d, new DateTime(2009, 12, 31)));

            Assert.AreEqual(7305, occurrences.Count);
        }
        public void Occurrences_crossing_start()
        {
            // 20/4, 23/4, 26/4, 29/4, 2/5, 5/5, 8/5
            DailySchedule day = new DailySchedule { Frequency = 3 };
            IList<DateTime> occurrences = Convert(day.GetOccurrences(_start, new DateTime(2010, 4, 1), new DateTime(2010, 4, 27)));

            Assert.AreEqual(3, occurrences.Count);
            Assert.AreEqual(occurrences[0], new DateTime(2010, 4, 20));
            Assert.AreEqual(occurrences[1], new DateTime(2010, 4, 23));
            Assert.AreEqual(occurrences[2], new DateTime(2010, 4, 26));
        }
        public void Occurrences_within_period()
        {
            // 20/4, 23/4, 26/4, 29/4, 2/5, 5/5, 8/5
            DailySchedule day = new DailySchedule { Frequency = 3 };
            IList<DateTime> occurrences = Convert(day.GetOccurrences(_start, new DateTime(2010, 4, 21), new DateTime(2010, 5, 2)));

            Assert.AreEqual(4, occurrences.Count);
            Assert.AreEqual(occurrences[0], new DateTime(2010, 4, 23));
            Assert.AreEqual(occurrences[1], new DateTime(2010, 4, 26));
            Assert.AreEqual(occurrences[2], new DateTime(2010, 4, 29));
            Assert.AreEqual(occurrences[3], new DateTime(2010, 5, 2));
        }
Пример #7
0
        public DailySchedule GetScheduleFor(DateTime date)
        {
            date = date.Date;

            DailySchedule schedule;

            if(!_schedules.TryGetValue(date, out schedule))
            {
                schedule = new DailySchedule {Date = date};
                schedule.BeginEdit();

                _schedules.Add(date, schedule);
            }

            return schedule;
        }
Пример #8
0
 public static DailySchedule CreateDailySchedule(global::System.Guid scheduleID, global::System.Guid tenantID, string name, global::System.DateTime startTime, global::System.DateTime creationTime, global::System.DateTime lastModifiedTime, bool isEnabled, byte dayInterval)
 {
     DailySchedule dailySchedule = new DailySchedule();
     dailySchedule.ScheduleID = scheduleID;
     dailySchedule.TenantID = tenantID;
     dailySchedule.Name = name;
     dailySchedule.StartTime = startTime;
     dailySchedule.CreationTime = creationTime;
     dailySchedule.LastModifiedTime = lastModifiedTime;
     dailySchedule.IsEnabled = isEnabled;
     dailySchedule.DayInterval = dayInterval;
     return dailySchedule;
 }
 /// <summary>
 /// Visitor pattern for generating description for this schedule.  Will update Description and fire events.
 /// </summary>
 public virtual void Visit(DailySchedule s) { OnDescriptionChanged(s, Format(s)); }