Shuttle.Cron 21.0.1

Prefix Reserved
dotnet add package Shuttle.Cron --version 21.0.1
                    
NuGet\Install-Package Shuttle.Cron -Version 21.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Shuttle.Cron" Version="21.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Shuttle.Cron" Version="21.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Shuttle.Cron" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Shuttle.Cron --version 21.0.1
                    
#r "nuget: Shuttle.Cron, 21.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Shuttle.Cron@21.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Shuttle.Cron&version=21.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Shuttle.Cron&version=21.0.1
                    
Install as a Cake Tool

Shuttle.Core.Cron

Provides cron expression parsing:

Installation

dotnet add package Shuttle.Core.Cron

Usage

 ┌───────────── minute (0 - 59)
 │ ┌─────────── hour (0 - 23)
 │ │ ┌───────── day of the month (1 - 31)
 │ │ │ ┌─────── month (1 - 12)
 │ │ │ │ ┌───── day of the week (1 - 7): Sunday to Saturday 
 │ │ │ │ │
 │ │ │ │ │
 * * * * *
using Shuttle.Core.Cron;

// Create a cron expression for every 5 minutes
var cron = new CronExpression("0/5 * * * *");

// Get next occurrence
var nextRun = cron.NextOccurrence();

// Get next occurrence from a specific date
var specificDate = new DateTime(2025, 1, 1, 10, 30, 0);
var nextFromSpecific = cron.GetNextOccurrence(specificDate);

// Get previous occurrence
var previousRun = cron.PreviousOccurrence();

// Example: Run at 2 AM on the last day of every month
var endOfMonthCron = new CronExpression("0 2 L * *");
var endOfMonthRun = endOfMonthCron.NextOccurrence();

CronExpression

public CronExpression(string expression, ISpecificationFactory? specificationFactory = null) : this(expression, DateTime.Now, specificationFactory);
public CronExpression(string expression, DateTime date, ISpecificationFactory? specificationFactory = null);

Creates a CronExpression instance and parses the given expression. The date specifies the root date from which to determine either the next or previous occurrence.

public DateTime NextOccurrence();
public DateTime NextOccurrence(DateTime date);

Returns the next date that would follow the given date. This is accomplished by adding 1 minute to the relevant date. If no date is provided the root date will be used. This method also sets the root date to the result.

public DateTime GetNextOccurrence(DateTime date);

Returns the next date that would follow the given date. If the given date satisfies the required specification(s) then the date is returned as-is.

public DateTime PreviousOccurrence();
public DateTime PreviousOccurrence(DateTime date);

Returns the previous date that would precede the given date. This is accomplished by subtracting 1 minute from the relevant date. If no date is provided the root date will be used. This method also sets the root date to the result.

public DateTime GetPreviousOccurrence(DateTime date);

Returns the previous date that would precede the given date. If the given date satisfies the required specification(s) then the date is returned as-is.

Cron Samples

Format is {minute} {hour} {day-of-month} {month} {day-of-week}

Field Options
minutes 0-59 , - * /
hours 0-23 , - * /
day-of-month 1-31 , - * ? / L W
month 1-12 or JAN-DEC , - * /
day-of-week 1-7 or SUN-SAT , - * ? / L #

If day-of-month is specified then day-of-week should be ? and vice-versa.

Examples:

* * * * * - is every minute of every hour of every day of every month
5,10-12,17/5 * * * * - minute 5, 10, 11, 12, and every 5th minute after that

Specifications

Specifications need to implement ISpecification<CronField.Candidate>.

You may pass an implementation of the ISpecificationFactory as a parameter to the CronExpression. There is a SpecificationFactory that accepts a function callback in the constructor for scenarios where an explicit ISpecificationFactory implementation may not be warranted, e.g.:

var factory = new SpecificationFactory(parameters =>
{
    return !parameters.Expression.Equals("H", StringComparison.InvariantCultureIgnoreCase) 
        ? null 
        : new Specification<CronField.Candidate>(candidate => candidate.Date.Day % 2 == 0);
});
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
21.0.1 73 4/15/2026
21.0.1-rc3 71 4/11/2026