using System.Collections.Generic;
using NCrontab.Advanced.Enumerations;
using NCrontab.Advanced.Filters;
using NCrontab.Advanced.Interfaces;
using CronExpressionDescriptor;
private static DateTime _start = DateTime.Parse("2017-01-01");
private static DateTime _end = DateTime.Parse("2017-12-31");
public static void Main()
var cron = "0 1 * * 1,2";
var cronInstance = CrontabSchedule.Parse(cron);
Console.WriteLine("Cron String: " + cron);
Console.WriteLine("\r\n-------------------------------------------------------------------");
Console.WriteLine(DetermineTimescale(cronInstance));
Console.WriteLine("\r\n-------------------------------------------------------------------");
Console.WriteLine(ExpressionDescriptor.GetDescription(cron));
Console.WriteLine("\r\n-------------------------------------------------------------------");
PrintOccurances(cronInstance);
public static void PrintOccurances(CrontabSchedule input)
var occurances = input.GetNextOccurrences(_start, _end);
foreach (var occurance in occurances)
Console.WriteLine(occurance);
public static TimeScale DetermineTimescale(CrontabSchedule input)
var minutes = input.Filters[CrontabFieldKind.Minute][0].ToString();
var hours = input.Filters[CrontabFieldKind.Hour][0].ToString();
var daymonth = input.Filters[CrontabFieldKind.Day][0].ToString();
var month = input.Filters[CrontabFieldKind.Month][0].ToString();
var dayweek = input.Filters[CrontabFieldKind.DayOfWeek][0].ToString();
if (new [] {hours, daymonth, month, dayweek}.All(x => x == "*"))
timeScale = TimeScale.Hourly;
if (new [] {daymonth, month, dayweek}.All(x => x == "*") && hours != "*")
timeScale = TimeScale.Daily;
timeScale = TimeScale.Weekly;
timeScale = TimeScale.Monthly;