A concrete implementation of DailyTimeIntervalTrigger that is used to fire a IJobDetail based upon daily repeating time intervals.

The trigger will fire every N (IDailyTimeIntervalTrigger.RepeatInterval ) seconds, minutes or hours (see IDailyTimeIntervalTrigger.RepeatInterval) during a given time window on specified days of the week.

For example#1, a trigger can be set to fire every 72 minutes between 8:00 and 11:00 everyday. It's fire times would be 8:00, 9:12, 10:24, then next day would repeat: 8:00, 9:12, 10:24 again.

For example#2, a trigger can be set to fire every 23 minutes between 9:20 and 16:47 Monday through Friday.

On each day, the starting fire time is reset to startTimeOfDay value, and then it will add repeatInterval value to it until the endTimeOfDay is reached. If you set daysOfWeek values, then fire time will only occur during those week days period. Again, remember this trigger will reset fire time each day with startTimeOfDay, regardless of your interval or endTimeOfDay!

The default values for fields if not set are: startTimeOfDay defaults to 00:00:00, the endTimeOfDay default to 23:59:59, and daysOfWeek is default to every day. The startTime default to current time-stamp now, while endTime has not value.

If startTime is before startTimeOfDay, then startTimeOfDay will be used and startTime has no affect. Else if startTime is after startTimeOfDay, then the first fire time for that day will be the next interval after the startTime. For example, if you set startingTimeOfDay=9am, endingTimeOfDay=11am, interval=15 mins, and startTime=9:33am, then the next fire time will be 9:45pm. Note also that if you do not set startTime value, the trigger builder will default to current time, and current time maybe before or after the startTimeOfDay! So be aware how you set your startTime.

This trigger also supports "repeatCount" feature to end the trigger fire time after a certain number of count is reached. Just as the SimpleTrigger, setting repeatCount=0 means trigger will fire once only! Setting any positive count then the trigger will repeat count + 1 times. Unlike SimpleTrigger, the default value of repeatCount of this trigger is set to REPEAT_INDEFINITELY instead of 0 though.

Наследование: AbstractTrigger, IDailyTimeIntervalTrigger, ICoreTrigger
        public void DayOfWeekPropertyShouldNotAffectOtherTriggers()
        {
            //make 2 trigger exactly the same
            DailyTimeIntervalTriggerImpl trigger1 = new DailyTimeIntervalTriggerImpl()
                                                    {
                                                        RepeatInterval = 1,
                                                        RepeatIntervalUnit = IntervalUnit.Hour
                                                    };

            DailyTimeIntervalTriggerImpl trigger2 = new DailyTimeIntervalTriggerImpl()
                                                    {
                                                        RepeatInterval = 1,
                                                        RepeatIntervalUnit = IntervalUnit.Hour
                                                    };

            //make an adjustment to only one trigger.
            //I only want mondays now
            trigger1.DaysOfWeek.Clear();
            trigger1.DaysOfWeek.Add(DayOfWeek.Monday);

            //check trigger 2 DOW
            //this fails because the reference collection only contains MONDAY b/c it was cleared.
            Assert.IsTrue(trigger2.DaysOfWeek.Contains(DayOfWeek.Monday));
            Assert.IsTrue(trigger2.DaysOfWeek.Contains(DayOfWeek.Tuesday));
            Assert.IsTrue(trigger2.DaysOfWeek.Contains(DayOfWeek.Wednesday));
            Assert.IsTrue(trigger2.DaysOfWeek.Contains(DayOfWeek.Thursday));
            Assert.IsTrue(trigger2.DaysOfWeek.Contains(DayOfWeek.Friday));
            Assert.IsTrue(trigger2.DaysOfWeek.Contains(DayOfWeek.Saturday));
            Assert.IsTrue(trigger2.DaysOfWeek.Contains(DayOfWeek.Sunday));
        }
        public void TestQuartzCalendarExclusion()
        {
            DateTimeOffset startTime = DateBuilder.DateOf(0, 0, 0, 1, 1, 2011);
            var trigger = new DailyTimeIntervalTriggerImpl
            {
                StartTimeUtc = startTime.ToUniversalTime(),
                StartTimeOfDay = new TimeOfDay(8, 0),
                RepeatIntervalUnit = IntervalUnit.Minute,
                RepeatInterval = 60
            };

            CronCalendar cronCal = new CronCalendar("* * 9-12 * * ?"); // exclude 9-12		
            IList<DateTimeOffset> fireTimes = TriggerUtils.ComputeFireTimes(trigger, cronCal, 48);
            Assert.AreEqual(48, fireTimes.Count);
            Assert.AreEqual(DateBuilder.DateOf(8, 0, 0, 1, 1, 2011), fireTimes[0]);
            Assert.AreEqual(DateBuilder.DateOf(13, 0, 0, 1, 1, 2011), fireTimes[1]);
            Assert.AreEqual(DateBuilder.DateOf(23, 0, 0, 4, 1, 2011), fireTimes[47]);
        }
        public void TestEndTimeAfterEndTimeOfDay()
        {
            DateTimeOffset startTime = DateBuilder.DateOf(0, 0, 0, 1, 1, 2011);
            DateTimeOffset endTime = DateBuilder.DateOf(18, 0, 0, 2, 1, 2011);
            TimeOfDay endTimeOfDay = new TimeOfDay(17, 0, 0);
            DailyTimeIntervalTriggerImpl trigger = new DailyTimeIntervalTriggerImpl();
            trigger.StartTimeUtc = startTime;
            trigger.EndTimeUtc = endTime;
            trigger.EndTimeOfDayUtc = endTimeOfDay;
            trigger.RepeatIntervalUnit = IntervalUnit.Minute;
            trigger.RepeatInterval = 60;

            IList<DateTimeOffset> fireTimes = TriggerUtils.ComputeFireTimes(trigger, null, 48);
            Assert.AreEqual(36, fireTimes.Count);
            Assert.AreEqual(DateBuilder.DateOf(0, 0, 0, 1, 1, 2011), fireTimes[0]);
            Assert.AreEqual(DateBuilder.DateOf(17, 0, 0, 1, 1, 2011), fireTimes[17]);
            Assert.AreEqual(DateBuilder.DateOf(17, 0, 0, 2, 1, 2011), fireTimes[35]);
        }
        public void TestNormalExample()
        {
            DateTimeOffset startTime = DateBuilder.DateOf(0, 0, 0, 1, 1, 2011);
            TimeOfDay startTimeOfDay = new TimeOfDay(8, 0, 0);
            TimeOfDay endTimeOfDay = new TimeOfDay(11, 0, 0);
            var trigger = new DailyTimeIntervalTriggerImpl
            {
                StartTimeUtc = startTime.ToUniversalTime(),
                StartTimeOfDay = startTimeOfDay,
                EndTimeOfDay = endTimeOfDay,
                RepeatIntervalUnit = IntervalUnit.Minute,
                RepeatInterval = 72 // this interval will give three firings per day (8:00, 9:12, and 10:24)
            };

            IList<DateTimeOffset> fireTimes = TriggerUtils.ComputeFireTimes(trigger, null, 48);
            Assert.AreEqual(48, fireTimes.Count);
            Assert.AreEqual(DateBuilder.DateOf(8, 0, 0, 1, 1, 2011), fireTimes[0]);
            Assert.AreEqual(DateBuilder.DateOf(10, 24, 0, 16, 1, 2011), fireTimes[47]);
        }
        public void TestAllDaysOfTheWeek()
        {
            Collection.ISet<DayOfWeek> daysOfWeek = DailyTimeIntervalScheduleBuilder.AllDaysOfTheWeek;
            DateTimeOffset startTime = DateBuilder.DateOf(0, 0, 0, 1, 1, 2011); // SAT
            TimeOfDay startTimeOfDay = new TimeOfDay(8, 0, 0);
            TimeOfDay endTimeOfDay = new TimeOfDay(17, 0, 0);
            DailyTimeIntervalTriggerImpl trigger = new DailyTimeIntervalTriggerImpl();
            trigger.StartTimeUtc = startTime;
            trigger.StartTimeOfDayUtc = startTimeOfDay;
            trigger.EndTimeOfDayUtc = endTimeOfDay;
            trigger.DaysOfWeek = daysOfWeek;
            trigger.RepeatIntervalUnit = IntervalUnit.Minute;
            trigger.RepeatInterval = 60;

            IList<DateTimeOffset> fireTimes = TriggerUtils.ComputeFireTimes(trigger, null, 48);
            Assert.AreEqual(48, fireTimes.Count);
            Assert.AreEqual(DateBuilder.DateOf(8, 0, 0, 1, 1, 2011), fireTimes[0]);
            Assert.AreEqual(DateBuilder.DateOf(17, 0, 0, 1, 1, 2011), fireTimes[9]); // The 10th hours is the end of day.
            Assert.AreEqual(DateBuilder.DateOf(15, 0, 0, 5, 1, 2011), fireTimes[47]);
        }
        public void TestSatAndSun()
        {
            Collection.ISet<DayOfWeek> daysOfWeek = DailyTimeIntervalScheduleBuilder.SaturdayAndSunday;
            DateTimeOffset startTime = DateBuilder.DateOf(0, 0, 0, 1, 1, 2011); // SAT(7)
            TimeOfDay startTimeOfDay = new TimeOfDay(8, 0, 0);
            TimeOfDay endTimeOfDay = new TimeOfDay(17, 0, 0);
            DailyTimeIntervalTriggerImpl trigger = new DailyTimeIntervalTriggerImpl();
            trigger.StartTimeUtc = startTime;
            trigger.StartTimeOfDayUtc = startTimeOfDay;
            trigger.EndTimeOfDayUtc = endTimeOfDay;
            trigger.DaysOfWeek = daysOfWeek;
            trigger.RepeatIntervalUnit = IntervalUnit.Minute;
            trigger.RepeatInterval = 60;

            IList<DateTimeOffset> fireTimes = TriggerUtils.ComputeFireTimes(trigger, null, 48);
            Assert.AreEqual(48, fireTimes.Count);
            Assert.AreEqual(DateBuilder.DateOf(8, 0, 0, 1, 1, 2011), fireTimes[0]);
            Assert.AreEqual(DayOfWeek.Saturday, fireTimes[0].DayOfWeek);
            Assert.AreEqual(DateBuilder.DateOf(8, 0, 0, 2, 1, 2011), fireTimes[10]);
            Assert.AreEqual(DayOfWeek.Sunday, fireTimes[10].DayOfWeek);
            Assert.AreEqual(DateBuilder.DateOf(15, 0, 0, 15, 1, 2011), fireTimes[47]);
            Assert.AreEqual(DayOfWeek.Saturday, fireTimes[47].DayOfWeek);
        }
 public void TestValidateTimeOfDayOrder()
 {
     var trigger = new DailyTimeIntervalTriggerImpl
     {
         StartTimeOfDay = new TimeOfDay(12, 0, 0),
         EndTimeOfDay = new TimeOfDay(8, 0, 0)
     };
     try
     {
         trigger.Validate();
         Assert.Fail("Trigger should be invalidate when time of day is not in order.");
     }
     catch (SchedulerException)
     {
         // expected.
     }
 }
        public void TestGetFireTimeWhenStartTimeAndTimeOfDayIsSame()
        {
            // A test case for QTZ-369
            DateTime startTime = new DateTime(2012, 1, 1);
            TimeOfDay startTimeOfDay = new TimeOfDay(8, 0, 0);
            TimeOfDay endTimeOfDay = new TimeOfDay(13, 0, 0);
            var trigger = new DailyTimeIntervalTriggerImpl();
            trigger.StartTimeUtc = startTime;
            trigger.StartTimeOfDay = startTimeOfDay;
            trigger.EndTimeOfDay = endTimeOfDay;
            trigger.RepeatIntervalUnit = IntervalUnit.Hour;
            trigger.RepeatInterval = 1;

            Assert.AreEqual(dateOf(8, 0, 0, 1, 1, 2012), trigger.GetFireTimeAfter(new DateTime(2012, 1, 1)));
        }
        public void TestGetFireTime()
        {
            DateTime startTime = new DateTime(2011, 1, 1);
            TimeOfDay startTimeOfDay = new TimeOfDay(8, 0, 0);
            TimeOfDay endTimeOfDay = new TimeOfDay(13, 0, 0);
            var trigger = new DailyTimeIntervalTriggerImpl();
            trigger.StartTimeUtc = startTime;
            trigger.StartTimeOfDay = startTimeOfDay;
            trigger.EndTimeOfDay = endTimeOfDay;
            trigger.RepeatIntervalUnit = IntervalUnit.Hour;
            trigger.RepeatInterval = 1;

            Assert.AreEqual(dateOf(8, 0, 0, 1, 1, 2011), trigger.GetFireTimeAfter(dateOf(0, 0, 0, 1, 1, 2011)));
            Assert.AreEqual(dateOf(8, 0, 0, 1, 1, 2011), trigger.GetFireTimeAfter(dateOf(7, 0, 0, 1, 1, 2011)));
            Assert.AreEqual(dateOf(8, 0, 0, 1, 1, 2011), trigger.GetFireTimeAfter(dateOf(7, 59, 59, 1, 1, 2011)));
            Assert.AreEqual(dateOf(9, 0, 0, 1, 1, 2011), trigger.GetFireTimeAfter(dateOf(8, 0, 0, 1, 1, 2011)));
            Assert.AreEqual(dateOf(10, 0, 0, 1, 1, 2011), trigger.GetFireTimeAfter(dateOf(9, 0, 0, 1, 1, 2011)));
            Assert.AreEqual(dateOf(13, 0, 0, 1, 1, 2011), trigger.GetFireTimeAfter(dateOf(12, 59, 59, 1, 1, 2011)));
            Assert.AreEqual(dateOf(8, 0, 0, 2, 1, 2011), trigger.GetFireTimeAfter(dateOf(13, 0, 0, 1, 1, 2011)));
        }
        public void TestRepeatCount0()
        {
            DateTimeOffset startTime = DateBuilder.DateOf(0, 0, 0, 1, 1, 2011);
            TimeOfDay startTimeOfDay = new TimeOfDay(8, 0, 0);
            TimeOfDay endTimeOfDay = new TimeOfDay(11, 0, 0);
            var trigger = new DailyTimeIntervalTriggerImpl
            {
                StartTimeUtc = startTime.ToUniversalTime(),
                StartTimeOfDay = startTimeOfDay,
                EndTimeOfDay = endTimeOfDay,
                RepeatIntervalUnit = IntervalUnit.Minute,
                RepeatInterval = 72,
                RepeatCount = 0
            };

            IList<DateTimeOffset> fireTimes = TriggerUtils.ComputeFireTimes(trigger, null, 48);
            Assert.AreEqual(1, fireTimes.Count);
            Assert.AreEqual(DateBuilder.DateOf(8, 0, 0, 1, 1, 2011), fireTimes[0]);
        }
        public void TestSecondInterval()
        {
            DateTimeOffset startTime = DateBuilder.DateOf(0, 0, 0, 1, 1, 2011);
            TimeOfDay startTimeOfDay = new TimeOfDay(8, 0, 2);
            TimeOfDay endTimeOfDay = new TimeOfDay(13, 30, 0);
            var trigger = new DailyTimeIntervalTriggerImpl
            {
                StartTimeUtc = startTime.ToUniversalTime(),
                StartTimeOfDay = startTimeOfDay,
                EndTimeOfDay = endTimeOfDay,
                RepeatIntervalUnit = IntervalUnit.Second,
                RepeatInterval = 72
            };

            IList<DateTimeOffset> fireTimes = TriggerUtils.ComputeFireTimes(trigger, null, 48);
            Assert.AreEqual(48, fireTimes.Count);
            Assert.AreEqual((DateBuilder.DateOf(8, 0, 2, 1, 1, 2011)), fireTimes[0]);
            Assert.AreEqual((DateBuilder.DateOf(8, 56, 26, 1, 1, 2011)), fireTimes[47]);
        }
        public void TestValidateInterval()
        {
            var trigger = new DailyTimeIntervalTriggerImpl
            {
                Name = "test",
                Group = "test",
                JobKey = JobKey.Create("test"),
                RepeatIntervalUnit = IntervalUnit.Hour,
                RepeatInterval = 25
            };

            Assert.Throws<SchedulerException>(trigger.Validate, "repeatInterval can not exceed 24 hours. Given 25 hours.");

            trigger.RepeatIntervalUnit = IntervalUnit.Minute;
            trigger.RepeatInterval = 60*25;
            Assert.Throws<SchedulerException>(trigger.Validate, "repeatInterval can not exceed 24 hours (86400 seconds). Given 90000");

            trigger.RepeatIntervalUnit = IntervalUnit.Second;
            trigger.RepeatInterval = 60*60*25;

            Assert.Throws<SchedulerException>(trigger.Validate, "repeatInterval can not exceed 24 hours (86400 seconds). Given 90000");

            Assert.Throws<ArgumentException>(delegate { trigger.RepeatIntervalUnit = IntervalUnit.Day; }, "Invalid repeat IntervalUnit (must be Second, Minute or Hour)");

            trigger.RepeatIntervalUnit = IntervalUnit.Second;
            trigger.RepeatInterval = 0;
            Assert.Throws<SchedulerException>(trigger.Validate, "Repeat Interval cannot be zero.");
        }
Пример #13
0
        public void Test(IScheduler scheduler, bool clearJobs, bool scheduleJobs)
        {
            try
               {
               if (clearJobs)
               {
                   scheduler.Clear();
               }

               if (scheduleJobs)
               {
                   ICalendar cronCalendar = new CronCalendar("0/5 * * * * ?");
                   ICalendar holidayCalendar = new HolidayCalendar();

                   // QRTZNET-86
                   ITrigger t = scheduler.GetTrigger(new TriggerKey("NonExistingTrigger", "NonExistingGroup"));
                   Assert.IsNull(t);

                   AnnualCalendar cal = new AnnualCalendar();
                   scheduler.AddCalendar("annualCalendar", cal, false, true);

                   IOperableTrigger calendarsTrigger = new SimpleTriggerImpl("calendarsTrigger", "test", 20, TimeSpan.FromMilliseconds(5));
                   calendarsTrigger.CalendarName = "annualCalendar";

                   JobDetailImpl jd = new JobDetailImpl("testJob", "test", typeof(NoOpJob));
                   scheduler.ScheduleJob(jd, calendarsTrigger);

                   // QRTZNET-93
                   scheduler.AddCalendar("annualCalendar", cal, true, true);

                   scheduler.AddCalendar("baseCalendar", new BaseCalendar(), false, true);
                   scheduler.AddCalendar("cronCalendar", cronCalendar, false, true);
                   scheduler.AddCalendar("dailyCalendar", new DailyCalendar(DateTime.Now.Date, DateTime.Now.AddMinutes(1)), false, true);
                   scheduler.AddCalendar("holidayCalendar", holidayCalendar, false, true);
                   scheduler.AddCalendar("monthlyCalendar", new MonthlyCalendar(), false, true);
                   scheduler.AddCalendar("weeklyCalendar", new WeeklyCalendar(), false, true);

                   scheduler.AddCalendar("cronCalendar", cronCalendar, true, true);
                   scheduler.AddCalendar("holidayCalendar", holidayCalendar, true, true);

                   Assert.IsNotNull(scheduler.GetCalendar("annualCalendar"));

                   JobDetailImpl lonelyJob = new JobDetailImpl("lonelyJob", "lonelyGroup", typeof(SimpleRecoveryJob));
                   lonelyJob.Durable = true;
                   lonelyJob.RequestsRecovery = true;
                   scheduler.AddJob(lonelyJob, false);
                   scheduler.AddJob(lonelyJob, true);

                   string schedId = scheduler.SchedulerInstanceId;

                   int count = 1;

                   JobDetailImpl job = new JobDetailImpl("job_" + count, schedId, typeof(SimpleRecoveryJob));

                   // ask scheduler to re-Execute this job if it was in progress when
                   // the scheduler went down...
                   job.RequestsRecovery = true;
                   IOperableTrigger trigger = new SimpleTriggerImpl("trig_" + count, schedId, 20, TimeSpan.FromSeconds(5));
                   trigger.JobDataMap.Add("key", "value");
                   trigger.EndTimeUtc = DateTime.UtcNow.AddYears(10);

                   trigger.StartTimeUtc = DateTime.Now.AddMilliseconds(1000L);
                   scheduler.ScheduleJob(job, trigger);

                   // check that trigger was stored
                   ITrigger persisted = scheduler.GetTrigger(new TriggerKey("trig_" + count, schedId));
                   Assert.IsNotNull(persisted);
                   Assert.IsTrue(persisted is SimpleTriggerImpl);

                   count++;
                   job = new JobDetailImpl("job_" + count, schedId, typeof(SimpleRecoveryJob));
                   // ask scheduler to re-Execute this job if it was in progress when
                   // the scheduler went down...
                   job.RequestsRecovery = (true);
                   trigger = new SimpleTriggerImpl("trig_" + count, schedId, 20, TimeSpan.FromSeconds(5));

                   trigger.StartTimeUtc = (DateTime.Now.AddMilliseconds(2000L));
                   scheduler.ScheduleJob(job, trigger);

                   count++;
                   job = new JobDetailImpl("job_" + count, schedId, typeof(SimpleRecoveryStatefulJob));
                   // ask scheduler to re-Execute this job if it was in progress when
                   // the scheduler went down...
                   job.RequestsRecovery = (true);
                   trigger = new SimpleTriggerImpl("trig_" + count, schedId, 20, TimeSpan.FromSeconds(3));

                   trigger.StartTimeUtc = (DateTime.Now.AddMilliseconds(1000L));
                   scheduler.ScheduleJob(job, trigger);

                   count++;
                   job = new JobDetailImpl("job_" + count, schedId, typeof(SimpleRecoveryJob));
                   // ask scheduler to re-Execute this job if it was in progress when
                   // the scheduler went down...
                   job.RequestsRecovery = (true);
                   trigger = new SimpleTriggerImpl("trig_" + count, schedId, 20, TimeSpan.FromSeconds(4));

                   trigger.StartTimeUtc = (DateTime.Now.AddMilliseconds(1000L));
                   scheduler.ScheduleJob(job, trigger);

                   count++;
                   job = new JobDetailImpl("job_" + count, schedId, typeof(SimpleRecoveryJob));
                   // ask scheduler to re-Execute this job if it was in progress when
                   // the scheduler went down...
                   job.RequestsRecovery = (true);
                   trigger = new SimpleTriggerImpl("trig_" + count, schedId, 20, TimeSpan.FromMilliseconds(4500));
                   scheduler.ScheduleJob(job, trigger);

                   count++;
                   job = new JobDetailImpl("job_" + count, schedId, typeof(SimpleRecoveryJob));
                   // ask scheduler to re-Execute this job if it was in progress when
                   // the scheduler went down...
                   job.RequestsRecovery = (true);
                   IOperableTrigger ct = new CronTriggerImpl("cron_trig_" + count, schedId, "0/10 * * * * ?");
                   ct.JobDataMap.Add("key", "value");
                   ct.StartTimeUtc = DateTime.Now.AddMilliseconds(1000);

                   scheduler.ScheduleJob(job, ct);

                   count++;
                   job = new JobDetailImpl("job_" + count, schedId, typeof(SimpleRecoveryJob));
                   // ask scheduler to re-Execute this job if it was in progress when
                   // the scheduler went down...
                   job.RequestsRecovery = (true);
                   DailyTimeIntervalTriggerImpl nt = new DailyTimeIntervalTriggerImpl("nth_trig_" + count, schedId, new TimeOfDay(1, 1, 1), new TimeOfDay(23, 30, 0), IntervalUnit.Hour, 1);
                   nt.StartTimeUtc = DateTime.Now.Date.AddMilliseconds(1000);

                   scheduler.ScheduleJob(job, nt);

                   DailyTimeIntervalTriggerImpl nt2 = new DailyTimeIntervalTriggerImpl();
                   nt2.Key = new TriggerKey("nth_trig2_" + count, schedId);
                   nt2.StartTimeUtc = DateTime.Now.Date.AddMilliseconds(1000);
                   nt2.JobKey = job.Key;
                   scheduler.ScheduleJob(nt2);

                   // GitHub issue #92
                   scheduler.GetTrigger(nt2.Key);

                   // GitHub issue #98
                   nt2.StartTimeOfDay = new TimeOfDay(1, 2, 3);
                   nt2.EndTimeOfDay = new TimeOfDay(2, 3, 4);

                   scheduler.UnscheduleJob(nt2.Key);
                   scheduler.ScheduleJob(nt2);

                   var triggerFromDb = (IDailyTimeIntervalTrigger) scheduler.GetTrigger(nt2.Key);
                   Assert.That(triggerFromDb.StartTimeOfDay.Hour, Is.EqualTo(1));
                   Assert.That(triggerFromDb.StartTimeOfDay.Minute, Is.EqualTo(2));
                   Assert.That(triggerFromDb.StartTimeOfDay.Second, Is.EqualTo(3));

                   Assert.That(triggerFromDb.EndTimeOfDay.Hour, Is.EqualTo(2));
                   Assert.That(triggerFromDb.EndTimeOfDay.Minute, Is.EqualTo(3));
                   Assert.That(triggerFromDb.EndTimeOfDay.Second, Is.EqualTo(4));

                   job.RequestsRecovery = (true);
                   CalendarIntervalTriggerImpl intervalTrigger = new CalendarIntervalTriggerImpl(
                       "calint_trig_" + count,
                       schedId,
                       DateTime.UtcNow.AddMilliseconds(300),
                       DateTime.UtcNow.AddMinutes(1),
                       IntervalUnit.Second,
                       8);
                   intervalTrigger.JobKey = job.Key;

                   scheduler.ScheduleJob(intervalTrigger);

                   // bulk operations
                   var info = new Dictionary<IJobDetail, Collection.ISet<ITrigger>>();
                   IJobDetail detail = new JobDetailImpl("job_" + count, schedId, typeof(SimpleRecoveryJob));
                   ITrigger simple = new SimpleTriggerImpl("trig_" + count, schedId, 20, TimeSpan.FromMilliseconds(4500));
                   var triggers = new Collection.HashSet<ITrigger>();
                   triggers.Add(simple);
                   info[detail] = triggers;

                   scheduler.ScheduleJobs(info, true);

                   Assert.IsTrue(scheduler.CheckExists(detail.Key));
                   Assert.IsTrue(scheduler.CheckExists(simple.Key));

                   // QRTZNET-243
                   scheduler.GetJobKeys(GroupMatcher<JobKey>.GroupContains("a").DeepClone());
                   scheduler.GetJobKeys(GroupMatcher<JobKey>.GroupEndsWith("a").DeepClone());
                   scheduler.GetJobKeys(GroupMatcher<JobKey>.GroupStartsWith("a").DeepClone());
                   scheduler.GetJobKeys(GroupMatcher<JobKey>.GroupEquals("a").DeepClone());

                   scheduler.GetTriggerKeys(GroupMatcher<TriggerKey>.GroupContains("a").DeepClone());
                   scheduler.GetTriggerKeys(GroupMatcher<TriggerKey>.GroupEndsWith("a").DeepClone());
                   scheduler.GetTriggerKeys(GroupMatcher<TriggerKey>.GroupStartsWith("a").DeepClone());
                   scheduler.GetTriggerKeys(GroupMatcher<TriggerKey>.GroupEquals("a").DeepClone());

                   scheduler.Start();

                   Thread.Sleep(TimeSpan.FromSeconds(3));

                   scheduler.PauseAll();

                   scheduler.ResumeAll();

                   scheduler.PauseJob(new JobKey("job_1", schedId));

                   scheduler.ResumeJob(new JobKey("job_1", schedId));

                   scheduler.PauseJobs(GroupMatcher<JobKey>.GroupEquals(schedId));

                   Thread.Sleep(TimeSpan.FromSeconds(1));

                   scheduler.ResumeJobs(GroupMatcher<JobKey>.GroupEquals(schedId));

                   scheduler.PauseTrigger(new TriggerKey("trig_2", schedId));
                   scheduler.ResumeTrigger(new TriggerKey("trig_2", schedId));

                   scheduler.PauseTriggers(GroupMatcher<TriggerKey>.GroupEquals(schedId));

                   Assert.AreEqual(1, scheduler.GetPausedTriggerGroups().Count);

                   Thread.Sleep(TimeSpan.FromSeconds(3));
                   scheduler.ResumeTriggers(GroupMatcher<TriggerKey>.GroupEquals(schedId));

                   Assert.IsNotNull(scheduler.GetTrigger(new TriggerKey("trig_2", schedId)));
                   Assert.IsNotNull(scheduler.GetJobDetail(new JobKey("job_1", schedId)));
                   Assert.IsNotNull(scheduler.GetMetaData());
                   Assert.IsNotNull(scheduler.GetCalendar("weeklyCalendar"));

                   Thread.Sleep(TimeSpan.FromSeconds(20));

                   scheduler.Standby();

                   CollectionAssert.IsNotEmpty(scheduler.GetCalendarNames());
                   CollectionAssert.IsNotEmpty(scheduler.GetJobKeys(GroupMatcher<JobKey>.GroupEquals(schedId)));

                   CollectionAssert.IsNotEmpty(scheduler.GetTriggersOfJob(new JobKey("job_2", schedId)));
                   Assert.IsNotNull(scheduler.GetJobDetail(new JobKey("job_2", schedId)));

                   scheduler.DeleteCalendar("cronCalendar");
                   scheduler.DeleteCalendar("holidayCalendar");
                   scheduler.DeleteJob(new JobKey("lonelyJob", "lonelyGroup"));
                   scheduler.DeleteJob(job.Key);

                   scheduler.GetJobGroupNames();
                   scheduler.GetCalendarNames();
                   scheduler.GetTriggerGroupNames();
               }
               }
               finally
               {
               scheduler.Shutdown(false);
               }
        }
        //http://www.cnblogs.com/Magicsky/archive/2012/02/07/2341637.html
        //http://blog.csdn.net/wanggang421338916/article/details/7412642
        public void Test()
        {
            //创建一个工作调度器工场
            ISchedulerFactory factory = new StdSchedulerFactory();
            //获取一个任务调度器
            IScheduler scheduler = factory.GetScheduler();
            scheduler.Start();
            //创建一个工作
            IJobDetail job = JobBuilder.Create<QuartzJobTest>().WithIdentity("SampleJob", "JobGroup1").Build();

            //创建触发器

            //1.服务开始时执行
            ITrigger trigger = TriggerBuilder.Create().StartNow().Build();

            //2.
            //该任务执行时间为每隔10秒中,如果要每隔5分钟可以这样0 0/5 * * * * ?
            //这样的格式表示每隔5分钟整执行
            ITrigger trigger5 = TriggerBuilder.Create()
                .WithIdentity("trigger1", "group1")
                .WithSchedule(CronScheduleBuilder.CronSchedule(new CronExpression("0/1 * * * * ?")))
                .Build();

            //2.在指定时间间隔内轮询执行
            //简单的调度作业,比如每隔一小时执行一次哪么简单调度器
            ITrigger trigger2= new SimpleTriggerImpl();
            //用的简单触发器,每隔5秒执行一次
            ITrigger trigger7 = TriggerBuilder.Create()
                .WithSimpleSchedule(t => t.RepeatForever().WithIntervalInSeconds(5))
                .WithIdentity("t1")
                .Build();

            //3.日轮询执行
            ITrigger trigger3 = new DailyTimeIntervalTriggerImpl("DailyTimeIntervalTrigger", DateTimeOffset.UtcNow, null, new TimeOfDay(1, 0, 0), new TimeOfDay(22, 01, 00), IntervalUnit.Minute, 1);

            //4.复杂的时间设定
            //
            ITrigger trigger4 = new CronTriggerImpl("CronTrigger", "TriggerGroup1", "0 0 12 * * ?");
            ITrigger trigger6 = TriggerBuilder.Create()
                .WithIdentity("trigger6", "group1")
                .WithCronSchedule("0/5 * 18 * * ? ")//每天每天下午的 6点到6点59分每隔5s就触发
                .Build();

            //任务与触发器添加到调度器
            scheduler.ScheduleJob(job, trigger);
        }
        public void TestStartTimeWithoutStartTimeOfDay()
        {
            DateTimeOffset startTime = DateBuilder.DateOf(0, 0, 0, 1, 1, 2011);
            DailyTimeIntervalTriggerImpl trigger = new DailyTimeIntervalTriggerImpl();
            trigger.StartTimeUtc = startTime;
            trigger.RepeatIntervalUnit = IntervalUnit.Minute;
            trigger.RepeatInterval = 60;

            IList<DateTimeOffset> fireTimes = TriggerUtils.ComputeFireTimes(trigger, null, 48);
            Assert.AreEqual(48, fireTimes.Count);
            Assert.AreEqual(DateBuilder.DateOf(0, 0, 0, 1, 1, 2011), fireTimes[0]);
            Assert.AreEqual(DateBuilder.DateOf(23, 0, 0, 2, 1, 2011), fireTimes[47]);
        }
        public void TestTimeOfDayWithEndTimeOddInterval()
        {
            DateTimeOffset startTime = DateBuilder.DateOf(0, 0, 0, 1, 1, 2011);
            DateTimeOffset endTime = DateBuilder.DateOf(0, 0, 0, 4, 1, 2011);
            TimeOfDay startTimeOfDay = new TimeOfDay(8, 0, 0);
            TimeOfDay endTimeOfDay = new TimeOfDay(10, 0, 0);
            var trigger = new DailyTimeIntervalTriggerImpl
            {
                StartTimeUtc = startTime.ToUniversalTime(),
                EndTimeUtc = endTime.ToUniversalTime(),
                StartTimeOfDay = startTimeOfDay,
                EndTimeOfDay = endTimeOfDay,
                RepeatIntervalUnit = IntervalUnit.Minute,
                RepeatInterval = 23
            };

            IList<DateTimeOffset> fireTimes = TriggerUtils.ComputeFireTimes(trigger, null, 48);
            Assert.AreEqual(18, fireTimes.Count);
            Assert.AreEqual(DateBuilder.DateOf(8, 0, 0, 1, 1, 2011), fireTimes[0]);
            Assert.AreEqual(DateBuilder.DateOf(9, 55, 0, 1, 1, 2011), fireTimes[5]);
            Assert.AreEqual(DateBuilder.DateOf(9, 55, 0, 3, 1, 2011), fireTimes[17]);
        }
        public void TestHourInterval()
        {
            DateTimeOffset startTime = DateBuilder.DateOf(0, 0, 0, 1, 1, 2011);
            DateTimeOffset endTime = DateBuilder.DateOf(13, 0, 0, 15, 1, 2011);
            TimeOfDay startTimeOfDay = new TimeOfDay(8, 1, 15);
            TimeOfDay endTimeOfDay = new TimeOfDay(16, 1, 15);
            var trigger = new DailyTimeIntervalTriggerImpl
            {
                StartTimeUtc = startTime.ToUniversalTime(),
                StartTimeOfDay = startTimeOfDay,
                EndTimeUtc = endTime.ToUniversalTime(),
                EndTimeOfDay = endTimeOfDay,
                RepeatIntervalUnit = IntervalUnit.Hour,
                RepeatInterval = 2
            };

            IList<DateTimeOffset> fireTimes = TriggerUtils.ComputeFireTimes(trigger, null, 48);
            Assert.AreEqual(48, fireTimes.Count);
            Assert.AreEqual(DateBuilder.DateOf(8, 1, 15, 1, 1, 2011), fireTimes[0]);
            Assert.AreEqual(DateBuilder.DateOf(12, 1, 15, 10, 1, 2011), fireTimes[47]);
        }
        public void TestStartTimeBeforeStartTimeOfDayOnInvalidDay()
        {
            DateTimeOffset startTime = dateOf(0, 0, 0, 1, 1, 2011); // Jan 1, 2011 was a saturday...
            TimeOfDay startTimeOfDay = new TimeOfDay(8, 0, 0);
            var trigger = new DailyTimeIntervalTriggerImpl();
            var daysOfWeek = new Collection.HashSet<DayOfWeek>
            {
                DayOfWeek.Monday,
                DayOfWeek.Tuesday,
                DayOfWeek.Wednesday,
                DayOfWeek.Thursday,
                DayOfWeek.Friday
            };
            trigger.DaysOfWeek = daysOfWeek;
            trigger.StartTimeUtc = startTime.ToUniversalTime();
            trigger.StartTimeOfDay = startTimeOfDay;
            trigger.RepeatIntervalUnit = IntervalUnit.Minute;
            trigger.RepeatInterval = 60;

            Assert.That(trigger.GetFireTimeAfter(dateOf(6, 0, 0, 22, 5, 2010)), Is.EqualTo(dateOf(8, 0, 0, 3, 1, 2011)));

            var fireTimes = TriggerUtils.ComputeFireTimes(trigger, null, 48);
            Assert.That(fireTimes.Count, Is.EqualTo(48));
            Assert.That(fireTimes[0], Is.EqualTo(dateOf(8, 0, 0, 3, 1, 2011)));
            Assert.That(fireTimes[47], Is.EqualTo(dateOf(23, 0, 0, 5, 1, 2011)));
        }
        public void TestRepeatCountInf()
        {
            DateTimeOffset startTime = DateBuilder.DateOf(0, 0, 0, 1, 1, 2011);
            TimeOfDay startTimeOfDay = new TimeOfDay(8, 0, 0);
            TimeOfDay endTimeOfDay = new TimeOfDay(11, 0, 0);
            var trigger = new DailyTimeIntervalTriggerImpl
            {
                StartTimeUtc = startTime.ToUniversalTime(),
                StartTimeOfDay = startTimeOfDay,
                EndTimeOfDay = endTimeOfDay,
                RepeatIntervalUnit = IntervalUnit.Minute,
                RepeatInterval = (72),
                RepeatCount = DailyTimeIntervalTriggerImpl.RepeatIndefinitely
            };

            // Setting this (which is default) should make the trigger just as normal one.

            IList<DateTimeOffset> fireTimes = TriggerUtils.ComputeFireTimes(trigger, null, 48);
            Assert.AreEqual(48, fireTimes.Count);
            Assert.AreEqual(DateBuilder.DateOf(8, 0, 0, 1, 1, 2011), fireTimes[0]);
            Assert.AreEqual(DateBuilder.DateOf(10, 24, 0, 16, 1, 2011), fireTimes[47]);
        }
        public void TestStartTimeAfterStartTimeOfDay()
        {
            DateTimeOffset startTime = DateBuilder.DateOf(9, 23, 0, 1, 1, 2011);
            TimeOfDay startTimeOfDay = new TimeOfDay(8, 0, 0);
            var trigger = new DailyTimeIntervalTriggerImpl
            {
                StartTimeUtc = startTime.ToUniversalTime(),
                StartTimeOfDay = startTimeOfDay,
                RepeatIntervalUnit = IntervalUnit.Minute,
                RepeatInterval = 60
            };

            IList<DateTimeOffset> fireTimes = TriggerUtils.ComputeFireTimes(trigger, null, 48);
            Assert.AreEqual(48, fireTimes.Count);
            Assert.AreEqual(DateBuilder.DateOf(10, 0, 0, 1, 1, 2011), fireTimes[0]);
            Assert.AreEqual(DateBuilder.DateOf(9, 0, 0, 4, 1, 2011), fireTimes[47]);
        }
        public void TestFollowsTimeZone2()
        {
            TimeZoneInfo est = TimeZoneUtil.FindTimeZoneById("Eastern Standard Time");

            DateTimeOffset startTime = new DateTimeOffset(2012, 11, 2, 12, 0, 0, TimeSpan.FromHours(-4));

            TimeOfDay startTimeOfDay = new TimeOfDay(8, 0, 0);
            TimeOfDay endTimeOfDay = new TimeOfDay(11, 0, 0);
            var trigger = new DailyTimeIntervalTriggerImpl
            {
                StartTimeUtc = startTime.ToUniversalTime(),
                StartTimeOfDay = startTimeOfDay,
                EndTimeOfDay = endTimeOfDay,
                RepeatIntervalUnit = IntervalUnit.Hour,
                RepeatInterval = 1,
                TimeZone = est
            };

            IList<DateTimeOffset> fireTimes = TriggerUtils.ComputeFireTimes(trigger, null, 8);

            DateTimeOffset expected0 = new DateTimeOffset(2012, 11, 3, 8, 0, 0, 0, TimeSpan.FromHours(-4));
            DateTimeOffset expected1 = new DateTimeOffset(2012, 11, 3, 9, 0, 0, 0, TimeSpan.FromHours(-4));
            DateTimeOffset expected2 = new DateTimeOffset(2012, 11, 3, 10, 0, 0, 0, TimeSpan.FromHours(-4));
            DateTimeOffset expected3 = new DateTimeOffset(2012, 11, 3, 11, 0, 0, 0, TimeSpan.FromHours(-4));

            DateTimeOffset expected4 = new DateTimeOffset(2012, 11, 4, 8, 0, 0, 0, TimeSpan.FromHours(-5));
            DateTimeOffset expected5 = new DateTimeOffset(2012, 11, 4, 9, 0, 0, 0, TimeSpan.FromHours(-5));
            DateTimeOffset expected6 = new DateTimeOffset(2012, 11, 4, 10, 0, 0, 0, TimeSpan.FromHours(-5));
            DateTimeOffset expected7 = new DateTimeOffset(2012, 11, 4, 11, 0, 0, 0, TimeSpan.FromHours(-5));

            Assert.AreEqual(expected0, fireTimes[0]);
            Assert.AreEqual(expected1, fireTimes[1]);
            Assert.AreEqual(expected2, fireTimes[2]);
            Assert.AreEqual(expected3, fireTimes[3]);
            Assert.AreEqual(expected4, fireTimes[4]);
            Assert.AreEqual(expected5, fireTimes[5]);
            Assert.AreEqual(expected6, fireTimes[6]);
            Assert.AreEqual(expected7, fireTimes[7]);
        }
        public void TestEndTimeBeforeEndTimeOfDay()
        {
            DateTimeOffset startTime = DateBuilder.DateOf(0, 0, 0, 1, 1, 2011);
            DateTimeOffset endTime = DateBuilder.DateOf(16, 0, 0, 2, 1, 2011);
            TimeOfDay endTimeOfDay = new TimeOfDay(17, 0, 0);
            var trigger = new DailyTimeIntervalTriggerImpl
            {
                StartTimeUtc = startTime.ToUniversalTime(),
                EndTimeUtc = endTime.ToUniversalTime(),
                EndTimeOfDay = endTimeOfDay,
                RepeatIntervalUnit = IntervalUnit.Minute,
                RepeatInterval = 60
            };

            IList<DateTimeOffset> fireTimes = TriggerUtils.ComputeFireTimes(trigger, null, 48);
            Assert.AreEqual(35, fireTimes.Count);
            Assert.AreEqual(DateBuilder.DateOf(0, 0, 0, 1, 1, 2011), fireTimes[0]);
            Assert.AreEqual(DateBuilder.DateOf(17, 0, 0, 1, 1, 2011), fireTimes[17]);
            Assert.AreEqual(DateBuilder.DateOf(16, 0, 0, 2, 1, 2011), fireTimes[34]);
        }
 public void ValidateShouldSucceedWithValidIntervalUnitHourConfiguration()
 {
     var trigger = new DailyTimeIntervalTriggerImpl
     {
         Name = "name",
         Group = "group",
         JobName = "jobname",
         JobGroup = "jobgroup",
         RepeatIntervalUnit = IntervalUnit.Hour
     };
     trigger.Validate();
 }
        public void TestTimeOfDayWithEndTime()
        {
            DateTimeOffset startTime = DateBuilder.DateOf(0, 0, 0, 1, 1, 2011);
            DateTimeOffset endTime = DateBuilder.DateOf(0, 0, 0, 4, 1, 2011);
            TimeOfDay startTimeOfDay = new TimeOfDay(8, 0, 0);
            TimeOfDay endTimeOfDay = new TimeOfDay(17, 0, 0);
            var trigger = new DailyTimeIntervalTriggerImpl
            {
                StartTimeUtc = startTime.ToUniversalTime(),
                EndTimeUtc = endTime.ToUniversalTime(),
                StartTimeOfDay = startTimeOfDay,
                EndTimeOfDay = endTimeOfDay,
                RepeatIntervalUnit = IntervalUnit.Minute,
                RepeatInterval = 60
            };

            IList<DateTimeOffset> fireTimes = TriggerUtils.ComputeFireTimes(trigger, null, 48);
            Assert.AreEqual(30, fireTimes.Count);
            Assert.AreEqual(DateBuilder.DateOf(8, 0, 0, 1, 1, 2011), fireTimes[0]);
            Assert.AreEqual(DateBuilder.DateOf(17, 0, 0, 1, 1, 2011), fireTimes[9]); // The 10th hours is the end of day.
            Assert.AreEqual(DateBuilder.DateOf(17, 0, 0, 3, 1, 2011), fireTimes[29]);
        }
        public void TestGetFireTimeWithDateBeforeStartTime()
        {
            DateTime startTime = new DateTime(2012, 1, 1);
            TimeOfDay startTimeOfDay = new TimeOfDay(8, 0, 0);
            TimeOfDay endTimeOfDay = new TimeOfDay(13, 0, 0);
            DailyTimeIntervalTriggerImpl trigger = new DailyTimeIntervalTriggerImpl();
            trigger.StartTimeUtc = startTime;
            trigger.StartTimeOfDay = startTimeOfDay;
            trigger.EndTimeOfDay = endTimeOfDay;
            trigger.RepeatIntervalUnit = IntervalUnit.Hour;
            trigger.RepeatInterval = 1;

            // NOTE that if you pass a date past the startTime, you will get the startTime back!
            Assert.AreEqual(dateOf(8, 0, 0, 1, 1, 2012), trigger.GetFireTimeAfter(dateOf(0, 0, 0, 1, 1, 2011)));
            Assert.AreEqual(dateOf(8, 0, 0, 1, 1, 2012), trigger.GetFireTimeAfter(dateOf(7, 0, 0, 1, 1, 2011)));
            Assert.AreEqual(dateOf(8, 0, 0, 1, 1, 2012), trigger.GetFireTimeAfter(dateOf(7, 59, 59, 1, 1, 2011)));
            Assert.AreEqual(dateOf(8, 0, 0, 1, 1, 2012), trigger.GetFireTimeAfter(dateOf(8, 0, 0, 1, 1, 2011)));
            Assert.AreEqual(dateOf(8, 0, 0, 1, 1, 2012), trigger.GetFireTimeAfter(dateOf(9, 0, 0, 1, 1, 2011)));
            Assert.AreEqual(dateOf(8, 0, 0, 1, 1, 2012), trigger.GetFireTimeAfter(dateOf(12, 59, 59, 1, 1, 2011)));
            Assert.AreEqual(dateOf(8, 0, 0, 1, 1, 2012), trigger.GetFireTimeAfter(dateOf(13, 0, 0, 1, 1, 2011)));

            // Now try some test times at or after startTime
            Assert.AreEqual(dateOf(8, 0, 0, 1, 1, 2012), trigger.GetFireTimeAfter(dateOf(0, 0, 0, 1, 1, 2012)));
            Assert.AreEqual(dateOf(8, 0, 0, 2, 1, 2012), trigger.GetFireTimeAfter(dateOf(13, 0, 0, 1, 1, 2012)));
        }
        public void TestTimeOfDayWithEndTime2()
        {
            DateTimeOffset startTime = DateBuilder.DateOf(0, 0, 0, 1, 1, 2011);
            TimeOfDay startTimeOfDay = new TimeOfDay(8, 23, 0);
            TimeOfDay endTimeOfDay = new TimeOfDay(23, 59, 59); // edge case when endTime is last second of day, which is default too.
            var trigger = new DailyTimeIntervalTriggerImpl
            {
                StartTimeUtc = startTime.ToUniversalTime(),
                StartTimeOfDay = startTimeOfDay,
                EndTimeOfDay = endTimeOfDay,
                RepeatIntervalUnit = IntervalUnit.Minute,
                RepeatInterval = 60
            };

            IList<DateTimeOffset> fireTimes = TriggerUtils.ComputeFireTimes(trigger, null, 48);
            Assert.AreEqual(48, fireTimes.Count);
            Assert.AreEqual(DateBuilder.DateOf(8, 23, 0, 1, 1, 2011), fireTimes[0]);
            Assert.AreEqual(DateBuilder.DateOf(23, 23, 0, 3, 1, 2011), fireTimes[47]);
        }
        public void TestExtraConstructors()
        {
            // A test case for QTZ-389 - some extra constructors didn't set all parameters
            DailyTimeIntervalTriggerImpl trigger = new DailyTimeIntervalTriggerImpl(
                "triggerName", "triggerGroup", "jobName", "jobGroup",
                dateOf(8, 0, 0, 1, 1, 2012), null,
                new TimeOfDay(8, 0, 0), new TimeOfDay(17, 0, 0),
                IntervalUnit.Hour, 1);

            Assert.AreEqual("triggerName", trigger.Name);
            Assert.AreEqual("triggerGroup", trigger.Group);
            Assert.AreEqual("jobName", trigger.JobName);
            Assert.AreEqual("jobGroup", trigger.JobGroup);
            Assert.AreEqual(dateOf(8, 0, 0, 1, 1, 2012), trigger.StartTimeUtc);
            Assert.AreEqual(null, trigger.EndTimeUtc);
            Assert.AreEqual(new TimeOfDay(8, 0, 0), trigger.StartTimeOfDay);
            Assert.AreEqual(new TimeOfDay(17, 0, 0), trigger.EndTimeOfDay);
            Assert.AreEqual(IntervalUnit.Hour, trigger.RepeatIntervalUnit);
            Assert.AreEqual(1, trigger.RepeatInterval);

            trigger = new DailyTimeIntervalTriggerImpl(
                "triggerName", "triggerGroup",
                dateOf(8, 0, 0, 1, 1, 2012), null,
                new TimeOfDay(8, 0, 0), new TimeOfDay(17, 0, 0),
                IntervalUnit.Hour, 1);

            Assert.AreEqual("triggerName", trigger.Name);
            Assert.AreEqual("triggerGroup", trigger.Group);
            Assert.AreEqual(null, trigger.JobName);
            Assert.AreEqual("DEFAULT", trigger.JobGroup);
            Assert.AreEqual(dateOf(8, 0, 0, 1, 1, 2012), trigger.StartTimeUtc);
            Assert.AreEqual(null, trigger.EndTimeUtc);
            Assert.AreEqual(new TimeOfDay(8, 0, 0), trigger.StartTimeOfDay);
            Assert.AreEqual(new TimeOfDay(17, 0, 0), trigger.EndTimeOfDay);
            Assert.AreEqual(IntervalUnit.Hour, trigger.RepeatIntervalUnit);
            Assert.AreEqual(1, trigger.RepeatInterval);
        }
        public void TestMonOnly()
        {
            Collection.ISet<DayOfWeek> daysOfWeek = new Collection.HashSet<DayOfWeek>();
            daysOfWeek.Add(DayOfWeek.Monday);
            DateTimeOffset startTime = DateBuilder.DateOf(0, 0, 0, 1, 1, 2011); // SAT(7)
            TimeOfDay startTimeOfDay = new TimeOfDay(8, 0, 0);
            TimeOfDay endTimeOfDay = new TimeOfDay(17, 0, 0);
            var trigger = new DailyTimeIntervalTriggerImpl
            {
                StartTimeUtc = startTime.ToUniversalTime(),
                StartTimeOfDay = startTimeOfDay,
                EndTimeOfDay = endTimeOfDay,
                DaysOfWeek = daysOfWeek,
                RepeatIntervalUnit = IntervalUnit.Minute,
                RepeatInterval = 60
            };

            IList<DateTimeOffset> fireTimes = TriggerUtils.ComputeFireTimes(trigger, null, 48);
            Assert.AreEqual(48, fireTimes.Count);
            Assert.AreEqual(DateBuilder.DateOf(8, 0, 0, 3, 1, 2011), fireTimes[0]);
            Assert.AreEqual(DayOfWeek.Monday, fireTimes[0].DayOfWeek);
            Assert.AreEqual(DateBuilder.DateOf(8, 0, 0, 10, 1, 2011), fireTimes[10]);
            Assert.AreEqual(DayOfWeek.Monday, fireTimes[10].DayOfWeek);
            Assert.AreEqual(DateBuilder.DateOf(15, 0, 0, 31, 1, 2011), fireTimes[47]);
            Assert.AreEqual(DayOfWeek.Monday, fireTimes[47].DayOfWeek);
        }
        public void ShouldGetScheduleBuilderWithSameSettingsAsTrigger()
        {
            var startTime = DateTimeOffset.UtcNow;
            var endTime = DateTimeOffset.UtcNow.AddDays(1);
            var startTimeOfDay = new TimeOfDay(1, 2, 3);
            var endTimeOfDay = new TimeOfDay(3, 2, 1);
            var trigger = new DailyTimeIntervalTriggerImpl("name", "group", startTime, endTime, startTimeOfDay, endTimeOfDay, IntervalUnit.Hour, 10);
            trigger.RepeatCount = 12;
            trigger.DaysOfWeek = new Collection.HashSet<DayOfWeek>
            {
                DayOfWeek.Thursday
            };
            trigger.MisfireInstruction = MisfireInstruction.DailyTimeIntervalTrigger.FireOnceNow;
            trigger.TimeZone = TimeZoneInfo.Utc;

            var scheduleBuilder = trigger.GetScheduleBuilder();

            var cloned = (DailyTimeIntervalTriggerImpl) scheduleBuilder.Build();
            CollectionAssert.AreEqual(cloned.DaysOfWeek, trigger.DaysOfWeek);
            Assert.That(cloned.RepeatCount, Is.EqualTo(trigger.RepeatCount));
            Assert.That(cloned.RepeatInterval, Is.EqualTo(trigger.RepeatInterval));
            Assert.That(cloned.RepeatIntervalUnit, Is.EqualTo(trigger.RepeatIntervalUnit));
            Assert.That(cloned.StartTimeOfDay, Is.EqualTo(trigger.StartTimeOfDay));
            Assert.That(cloned.EndTimeOfDay, Is.EqualTo(trigger.EndTimeOfDay));
            Assert.That(cloned.TimeZone, Is.EqualTo(trigger.TimeZone));
        }
        public void TestRepeatCount()
        {
            DateTimeOffset startTime = DateBuilder.DateOf(0, 0, 0, 1, 1, 2011);
            TimeOfDay startTimeOfDay = new TimeOfDay(8, 0, 0);
            TimeOfDay endTimeOfDay = new TimeOfDay(11, 0, 0);
            DailyTimeIntervalTriggerImpl trigger = new DailyTimeIntervalTriggerImpl();
            trigger.StartTimeUtc = startTime;
            trigger.StartTimeOfDayUtc = startTimeOfDay;
            trigger.EndTimeOfDayUtc = endTimeOfDay;
            trigger.RepeatIntervalUnit = IntervalUnit.Minute;
            trigger.RepeatInterval = 72;
            trigger.RepeatCount = 7;

            IList<DateTimeOffset> fireTimes = TriggerUtils.ComputeFireTimes(trigger, null, 48);
            Assert.AreEqual(8, fireTimes.Count);
            Assert.AreEqual(DateBuilder.DateOf(8, 0, 0, 1, 1, 2011), fireTimes[0]);
            Assert.AreEqual(DateBuilder.DateOf(9, 12, 0, 3, 1, 2011), fireTimes[7]);
        }