public void CronTimeGeneratorTests() { DateTime _dateTime = new DateTime(2016, 01, 01, 0, 0, 1); var stream = (CronTimeStreamComplex)CronStream.CreateSchedule(DaysOfWeek.Monday, "9p"); var template = stream.CronTemplates.First(); var times = CronTimeGenerator.Generate(_dateTime, template).Take(10).ToList(); Debug.WriteLine(times[0].DateTime.Value.ToString("yyyy-MM-dd ddd hh:mm:ss tt")); times[0].DateTime.Value.Should().Be(new DateTime(2016, 01, 04, 21, 0, 0)); times[1].DateTime.Value.Should().Be(new DateTime(2016, 01, 11, 21, 0, 0)); }
public CronTimeAggregateGeneratorTests() { var breakTemplate = new CronTemplateBuilder() .WithMinutes(0, 15, 30) .WithHours(9, 14) .WithAllDaysOfMonth() .WithDaysOfWeek(1, 2, 3, 4, 5) .WithAllMonths() .Build(); var hourlyTemplate = new CronTemplateBuilder() .WithMinutes(0) .WithHours(11, 12, 13, 16, 17) .WithAllDaysOfMonth() .WithDaysOfWeek(1, 2, 3, 4, 5) .WithAllMonths() .Build(); _nextTimes = CronTimeGenerator .Generate(new DateTime(2016, 01, 01), breakTemplate, hourlyTemplate); }
public void DontDropUpcomingCronTimesWhenTwoCronTemplatesGenerateTheSameTime() { var every3Minutes = new CronTemplateBuilder().WithEverything().WithSeconds(0).EveryXMinutes(3).Build(); var every4Minutes = new CronTemplateBuilder().WithEverything().WithSeconds(0).EveryXMinutes(4).Build(); var nextTimes = CronTimeGenerator .Generate(DateTime.MinValue, every3Minutes, every4Minutes) .Take(100) .ToList(); foreach (var nextTime in nextTimes) { PrintTime(nextTime); } var expectedValues3 = Enumerable.Range(1, 20).Select(z => z * 3).Where(z => z < 60).ToList(); var expectedValues4 = Enumerable.Range(1, 20).Select(z => z * 4).Where(z => z < 60).ToList(); var expectedValues = new SortedSet <int>(expectedValues3.Union(expectedValues4)).Take(100).ToList(); for (int i = 0; i < expectedValues.Count; i++) { nextTimes[i].Time.Minute.Should().Be(expectedValues[i]); } }
public override IEnumerator <CronTime> GetEnumerator() { return(CronTimeGenerator.Generate(_dateTime, CronTemplates).GetEnumerator()); }