NCrontab.Signed
3.4.0
dotnet add package NCrontab.Signed --version 3.4.0
NuGet\Install-Package NCrontab.Signed -Version 3.4.0
<PackageReference Include="NCrontab.Signed" Version="3.4.0" />
<PackageVersion Include="NCrontab.Signed" Version="3.4.0" />Directory.Packages.props
<PackageReference Include="NCrontab.Signed" />Project file
paket add NCrontab.Signed --version 3.4.0
#r "nuget: NCrontab.Signed, 3.4.0"
#:package NCrontab.Signed@3.4.0
#addin nuget:?package=NCrontab.Signed&version=3.4.0Install as a Cake Addin
#tool nuget:?package=NCrontab.Signed&version=3.4.0Install as a Cake Tool
NCrontab: Crontab for .NET
NCrontab is a library written in C# targeting .NET Standard Library 1.0 and that provides the following facilities:
- Parsing of crontab expressions
- Formatting of crontab expressions
- Calculation of occurrences of time based on a crontab schedule
This library does not provide any scheduler or is not a scheduling facility like cron from Unix platforms. What it provides is parsing, formatting and an algorithm to produce occurrences of time based on a give schedule expressed in the crontab format:
* * * * *
- - - - -
| | | | |
| | | | +----- day of week (0 - 6) (Sunday=0)
| | | +------- month (1 - 12)
| | +--------- day of month (1 - 31)
| +----------- hour (0 - 23)
+------------- min (0 - 59)
or a six-part format that allows for seconds:
* * * * * *
- - - - - -
| | | | | |
| | | | | +--- day of week (0 - 6) (Sunday=0)
| | | | +----- month (1 - 12)
| | | +------- day of month (1 - 31)
| | +--------- hour (0 - 23)
| +----------- min (0 - 59)
+------------- sec (0 - 59)
Star (*) in the value field above means all legal values as in parentheses for
that column. The value column can have a * or a list of elements separated by
commas. An element is either a number in the ranges shown above or two numbers in
the range separated by a hyphen (meaning an inclusive range). For more, see
CrontabExpression.
The default format parsed by CrontabSchedule.Parse is the five-part cron
format. In order to use the six-part format that includes seconds, pass a
CrontabSchedule.ParseOptions to Parse with IncludingSeconds set to
true. For example:
var s = CrontabSchedule.Parse("0,30 * * * * *",
new CrontabSchedule.ParseOptions
{
IncludingSeconds = true
});
Below is an example in IronPython of how to use CrontabSchedule class
from NCrontab to generate occurrences of the schedule 0 12 * */2 Mon
(meaning, 12:00 PM on Monday of every other month, starting with January)
throughout the year 2000:
IronPython 1.1 (1.1) on .NET 2.0.50727.1434
Copyright (c) Microsoft Corporation. All rights reserved.
>>> import clr
>>> clr.AddReferenceToFileAndPath(r'C:\NCrontab\bin\Release\NCrontab.dll')
>>> from System import DateTime
>>> from NCrontab import CrontabSchedule
>>> s = CrontabSchedule.Parse('0 12 * */2 Mon')
>>> start = DateTime(2000, 1, 1)
>>> end = start.AddYears(1)
>>> occurrences = s.GetNextOccurrences(start, end)
>>> print '\n'.join([t.ToString('ddd, dd MMM yyyy HH:mm') for t in occurrences])
2000年1月03日 12:00
2000年1月10日 12:00
2000年1月17日 12:00
2000年1月24日 12:00
2000年1月31日 12:00
2000年3月06日 12:00
2000年3月13日 12:00
2000年3月20日 12:00
2000年3月27日 12:00
2000年5月01日 12:00
2000年5月08日 12:00
2000年5月15日 12:00
2000年5月22日 12:00
2000年5月29日 12:00
2000年7月03日 12:00
2000年7月10日 12:00
2000年7月17日 12:00
2000年7月24日 12:00
2000年7月31日 12:00
2000年9月04日 12:00
2000年9月11日 12:00
2000年9月18日 12:00
2000年9月25日 12:00
2000年11月06日 12:00
2000年11月13日 12:00
2000年11月20日 12:00
2000年11月27日 12:00
Below is the same example in F# Interactive (fsi.exe):
Microsoft (R) F# 2.0 Interactive build 4.0.40219.1
Copyright (c) Microsoft Corporation. All Rights Reserved.
For help type #help;;
> #r "NCrontab.dll"
-
- open NCrontab
- open System
-
- let schedule = CrontabSchedule.Parse("0 12 * */2 Mon")
- let startDate = DateTime(2000, 1, 1)
- let endDate = startDate.AddYears(1)
-
- let occurrences = schedule.GetNextOccurrences(startDate, endDate)
- occurrences |> Seq.map (fun t -> t.ToString("ddd, dd MMM yyy HH:mm"))
- |> String.concat "\n"
- |> printfn "%s";;
--> Referenced 'C:\NCrontab\bin\Release\NCrontab.dll'
2000年1月03日 12:00
2000年1月10日 12:00
2000年1月17日 12:00
2000年1月24日 12:00
2000年1月31日 12:00
2000年3月06日 12:00
2000年3月13日 12:00
2000年3月20日 12:00
2000年3月27日 12:00
2000年5月01日 12:00
2000年5月08日 12:00
2000年5月15日 12:00
2000年5月22日 12:00
2000年5月29日 12:00
2000年7月03日 12:00
2000年7月10日 12:00
2000年7月17日 12:00
2000年7月24日 12:00
2000年7月31日 12:00
2000年9月04日 12:00
2000年9月11日 12:00
2000年9月18日 12:00
2000年9月25日 12:00
2000年11月06日 12:00
2000年11月13日 12:00
2000年11月20日 12:00
2000年11月27日 12:00
Below is the same example in C# Interactive (csi.exe):
Microsoft (R) Visual C# Interactive Compiler version 1.2.0.60317
Copyright (C) Microsoft Corporation. All rights reserved.
Type "#help" for more information.
> #r "NCrontab.dll"
> using NCrontab;
> var s = CrontabSchedule.Parse("0 12 * */2 Mon");
> var start = new DateTime(2000, 1, 1);
> var end = start.AddYears(1);
> var occurrences = s.GetNextOccurrences(start, end);
> Console.WriteLine(string.Join(Environment.NewLine,
. from t in occurrences
. select $"{t:ddd, dd MMM yyyy HH:mm}"));
2000年1月03日 12:00
2000年1月10日 12:00
2000年1月17日 12:00
2000年1月24日 12:00
2000年1月31日 12:00
2000年3月06日 12:00
2000年3月13日 12:00
2000年3月20日 12:00
2000年3月27日 12:00
2000年5月01日 12:00
2000年5月08日 12:00
2000年5月15日 12:00
2000年5月22日 12:00
2000年5月29日 12:00
2000年7月03日 12:00
2000年7月10日 12:00
2000年7月17日 12:00
2000年7月24日 12:00
2000年7月31日 12:00
2000年9月04日 12:00
2000年9月11日 12:00
2000年9月18日 12:00
2000年9月25日 12:00
2000年11月06日 12:00
2000年11月13日 12:00
2000年11月20日 12:00
2000年11月27日 12:00
Below is the same example in C# using dotnet-script:
> #r "nuget:NCrontab"
> using NCrontab;
> var s = CrontabSchedule.Parse("0 12 * */2 Mon");
> var start = new DateTime(2000, 1, 1);
> var end = start.AddYears(1);
> var occurrences = s.GetNextOccurrences(start, end);
> Console.WriteLine(string.Join(Environment.NewLine,
* from t in occurrences
* select $"{t:ddd, dd MMM yyyy HH:mm}"));
2000年1月03日 12:00
2000年1月10日 12:00
2000年1月17日 12:00
2000年1月24日 12:00
2000年1月31日 12:00
2000年3月06日 12:00
2000年3月13日 12:00
2000年3月20日 12:00
2000年3月27日 12:00
2000年5月01日 12:00
2000年5月08日 12:00
2000年5月15日 12:00
2000年5月22日 12:00
2000年5月29日 12:00
2000年7月03日 12:00
2000年7月10日 12:00
2000年7月17日 12:00
2000年7月24日 12:00
2000年7月31日 12:00
Mon, 04 Sept 2000 12:00
Mon, 11 Sept 2000 12:00
Mon, 18 Sept 2000 12:00
Mon, 25 Sept 2000 12:00
2000年11月06日 12:00
2000年11月13日 12:00
2000年11月20日 12:00
2000年11月27日 12:00
Some complex schedules cannot be expressed in a single crontab expression so
NCrontab can produce distinct occurrences given a sequence of
CrontabSchedule instances. In the C# example below, two schedules are merged
to produce a single set of occurrences over a week. The first schedule occurs
every 6 hours on weekdays while the second occurs every 12 hours on weekends.
Microsoft (R) Visual C# Interactive Compiler version 1.2.0.60317
Copyright (C) Microsoft Corporation. All rights reserved.
Type "#help" for more information.
> using NCrontab;
> var s1 = CrontabSchedule.Parse("0 */6 * * Mon-Fri");
> var s2 = CrontabSchedule.Parse("0 */12 * * Sat,Sun");
> var s = new[] { s1, s2 };
> var start = new DateTime(2000, 1, 1);
> var end = start.AddDays(7);
> var occurrences = s.GetNextOccurrences(start, end);
> // `2000年1月01日 10:00` won't appear because `start` is exclusive
> Console.WriteLine(string.Join(Environment.NewLine,
. from t in occurrences
. select $"{t:ddd, dd MMM yyyy HH:mm}"));
2000年1月01日 12:00
2000年1月02日 00:00
2000年1月02日 12:00
2000年1月03日 00:00
2000年1月03日 06:00
2000年1月03日 12:00
2000年1月03日 18:00
2000年1月04日 00:00
2000年1月04日 06:00
2000年1月04日 12:00
2000年1月04日 18:00
2000年1月05日 00:00
2000年1月05日 06:00
2000年1月05日 12:00
2000年1月05日 18:00
2000年1月06日 00:00
2000年1月06日 06:00
2000年1月06日 12:00
2000年1月06日 18:00
2000年1月07日 00:00
2000年1月07日 06:00
2000年1月07日 12:00
2000年1月07日 18:00
If one or more schedules produce the same occurrence then only one of them if returned.
Merging Schedules
NCrontab can merge the timeline of one or more schedules. This can sometimes come handy when it's impossible to express a schedule with a single crontab expression like every 6 hours from 9 AM to 5 PM, on weekdays, but at noon on weekends. By breaking it up into two schedules:
0 12 * * Sat-Sun: at noon on weekends0 9-17/6 * * Mon-Fri: every 6 hours from 9 AM to 5 PM on weekdays
you can merge them to produce a single timeline:
using System;
using NCrontab;
var start = new DateTime(2000, 1, 1);
var end = start.AddYears(1);
var schedules = new[]
{
CrontabSchedule.Parse("0 12 * * Sat-Sun"),
CrontabSchedule.Parse("0 9-17/6 * * Mon-Fri")
};
var occurrences = schedules.GetNextOccurrences(start, end);
Console.WriteLine(string.Join(Environment.NewLine,
from t in occurrences
select $"{t:ddd, dd MMM yyyy HH:mm}"));
The output from a run will:
2000年1月01日 12:00
2000年1月02日 12:00
2000年1月03日 09:00
2000年1月03日 12:00
2000年1月03日 15:00
2000年1月04日 09:00
2000年1月04日 12:00
2000年1月04日 15:00
2000年1月05日 09:00
2000年1月05日 12:00
2000年1月05日 15:00
2000年1月06日 09:00
2000年1月06日 12:00
2000年1月06日 15:00
2000年1月07日 09:00
2000年1月07日 12:00
2000年1月07日 15:00
2000年1月08日 12:00
2000年1月09日 12:00
...
If two or more schedules produce the same occurrence then only one of them is returned.
This product includes software developed by the OpenSymphony Group.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
| .NET Core | netcoreapp1.0 was computed. netcoreapp1.1 was computed. netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard1.0 is compatible. netstandard1.1 was computed. netstandard1.2 was computed. netstandard1.3 was computed. netstandard1.4 was computed. netstandard1.5 was computed. netstandard1.6 was computed. netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net35 is compatible. net40 was computed. net403 was computed. net45 was computed. net451 was computed. net452 was computed. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen30 was computed. tizen40 was computed. tizen60 was computed. |
| Universal Windows Platform | uap was computed. uap10.0 was computed. |
| Windows Phone | wp8 was computed. wp81 was computed. wpa81 was computed. |
| Windows Store | netcore was computed. netcore45 was computed. netcore451 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 3.5
-
.NETStandard 1.0
- NETStandard.Library (>= 1.6.1)
- System.Collections (>= 4.3.0)
- System.Diagnostics.Debug (>= 4.3.0)
- System.Globalization (>= 4.3.0)
- System.IO (>= 4.3.0)
- System.Net.Primitives (>= 4.3.1)
- System.Resources.ResourceManager (>= 4.3.0)
-
.NETStandard 2.0
- No dependencies.
NuGet packages (40)
Showing the top 5 NuGet packages that depend on NCrontab.Signed:
| Package | Downloads |
|---|---|
|
Microsoft.Azure.WebJobs.Extensions
This package contains Timers and File triggers. For more information, please visit https://azure.microsoft.com/en-us/documentation/articles/websites-webjobs-resources. |
|
|
MPACKAGE.LibDomain
Package Description |
|
|
Aspire.Hosting.Azure.AppContainers
Azure container apps resource types for Aspire. |
|
|
Aspire.Hosting.Azure.ContainerRegistry
Azure Container Registry resource types for Aspire. |
|
|
Aj.Platform.Core
Biblioteca de Uso Geral para integrações com as API OmsAj |
GitHub repositories (5)
Showing the top 5 popular GitHub repositories that depend on NCrontab.Signed:
| Repository | Stars |
|---|---|
|
microsoft/aspire
Aspire is the tool for code-first, extensible, observable dev and deploy.
|
|
|
smartstore/Smartstore
A modular, scalable and ultra-fast open-source all-in-one eCommerce platform built on ASP.NET Core 10
|
|
|
WindowsGSM/WindowsGSM
🎲 A powerful tool to manage game servers. Equipped with a GUI for server admins to install, import, start, stop, restart, update, and automate multiple servers with a push of a button.
|
|
|
Azure/azure-webjobs-sdk-extensions
Azure WebJobs SDK Extensions
|
|
|
markjprice/apps-services-net8
Repository for the Packt Publishing book titled "Apps and Services with .NET 8" by Mark J. Price
|