Frank.CronJobs.Cron 2.0.8-preview

This is a prerelease version of Frank.CronJobs.Cron.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Frank.CronJobs.Cron --version 2.0.8-preview                
NuGet\Install-Package Frank.CronJobs.Cron -Version 2.0.8-preview                
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="Frank.CronJobs.Cron" Version="2.0.8-preview" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Frank.CronJobs.Cron --version 2.0.8-preview                
#r "nuget: Frank.CronJobs.Cron, 2.0.8-preview"                
#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.
// Install Frank.CronJobs.Cron as a Cake Addin
#addin nuget:?package=Frank.CronJobs.Cron&version=2.0.8-preview&prerelease

// Install Frank.CronJobs.Cron as a Cake Tool
#tool nuget:?package=Frank.CronJobs.Cron&version=2.0.8-preview&prerelease                

Frank.CronJobs.Cron

Frank.CronJobs.Cron is a .NET library that provides cron expression parsing and scheduling capabilities. Its meant as an internal dependency for Frank.CronJobs, but works just fine as a CronParser

Features

  • Parse cron expressions and validate syntax
  • Calculate next occurrence datetime based on cron expression
  • Determine if cron expression is due relative to specified datetime
  • Helper methods for working with cron expressions
  • Constants for common Cron Expressions

Usage

Parse and validate cron expression

string expression = "0 15 10 * * ?";

CronExpression cron = new CronExpression(expression);

bool isValid = cron.IsValid;

Calculate next occurrence

string expression = "0 15 10 * * ?";

DateTime next = CronExpression.GetNextOccurrence(expression);

Check if cron is due

string expression = "0 15 10 * * *";
DateTime dateTime = new DateTime(2023, 2, 15, 11, 0, 0);

bool isDue = CronExpression.IsDue(expression, dateTime); // true

Use helper methods

// Get next occurrence from current time
DateTime next = CronHelper.GetNextOccurrence(expression);

// Get time until next occurrence 
TimeSpan timeToNext = CronHelper.GetTimeUntilNextOccurrence(expression);

// Check if due
bool isDue = CronHelper.IsDue(expression);

Use common cron expressions

string everySecond = PredefinedCronExpressions.EverySecond;
string everyMinute = PredefinedCronExpressions.EveryMinute;
string everyHour = PredefinedCronExpressions.EveryHour;
string everyDay = PredefinedCronExpressions.EveryDay;
string everyWeek = PredefinedCronExpressions.EveryWeek;
string everyMonth = PredefinedCronExpressions.EveryMonth;
string everyYear = PredefinedCronExpressions.EveryYear;

string everyYearOnChristmasEve = PredefinedCronExpressions.EveryYearOn.ChristmasEve;

Installation

Install the NuGet package directly from the package manager console:

PM> Install-Package Frank.CronJobs.Cron

License

Frank.CronJobs.Cron is licensed under the MIT license.

Contributing

Contributions, except for actual bug fixes, are not welcome at this time. This is an internal dependency for Frank.CronJobs, and though it is a standalone library, it is not meant to be developed as such. If you have a bug fix, please submit a pull with a test that demonstrates the bug and the fix.

Credits

This library is based on CronQuery, which I am a contributor to. This is built on that code to change it in a few ways to better suit my needs for Frank.CronJobs, and make it a standalone library so the lightweight cron parsing can be used in other projects as well with no dependencies.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Frank.CronJobs.Cron:

Package Downloads
Frank.CronJobs

Frank.CronJobs is a library for running cron jobs in .NET Core applications.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.9-preview 92 7/11/2024
2.0.8-preview 95 6/24/2024
2.0.0 166 2/3/2024
1.1.7-preview 87 2/3/2024
1.1.6-preview 104 1/29/2024
1.1.5-preview 108 1/24/2024
1.1.0 134 1/21/2024
1.0.4-preview 96 1/21/2024