it:ad:ncrontab:home

IT:AD:NCronTab

Summary

When you want a library to parse a Cron schedule, without the scheduling part, then you can use the NCronTab library.

void Main()
{
    //Consider checking the schedule in the worker, and not the db (!).
    //add a single column to the Adapter Column, and call it schedule... eg: to happen at 2:05am:
    var exampleAdapterRecord =new {Id=123,Schedule="05 02 * * *", Etc="..."};
    //Check for what's happening within the next minute, or next n days:
    var schedule = NCrontab.CrontabSchedule.Parse(exampleAdapterRecord.Schedule);
    var next = schedule.GetNextOccurrences(DateTime.Now, startTime.AddDays(3));
    foreach(var x in next){ x.Dump();}
}

Output of above would be:

27/08/2015 2:05:00 a.m.
28/08/2015 2:05:00 a.m.
29/08/2015 2:05:00 a.m.

  • /home/skysigal/public_html/data/pages/it/ad/ncrontab/home.txt
  • Last modified: 2023/11/04 03:27
  • by 127.0.0.1