Sparkdo.Crontab 2.0.0-preview.2

This is a prerelease version of Sparkdo.Crontab.
dotnet add package Sparkdo.Crontab --version 2.0.0-preview.2
                    
NuGet\Install-Package Sparkdo.Crontab -Version 2.0.0-preview.2
                    
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="Sparkdo.Crontab" Version="2.0.0-preview.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Sparkdo.Crontab" Version="2.0.0-preview.2" />
                    
Directory.Packages.props
<PackageReference Include="Sparkdo.Crontab" />
                    
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 Sparkdo.Crontab --version 2.0.0-preview.2
                    
#r "nuget: Sparkdo.Crontab, 2.0.0-preview.2"
                    
#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 Sparkdo.Crontab@2.0.0-preview.2
                    
#: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=Sparkdo.Crontab&version=2.0.0-preview.2&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Sparkdo.Crontab&version=2.0.0-preview.2&prerelease
                    
Install as a Cake Tool

Sparkdo.Crontab

Sparkdo.Crontab 是 .NET 10 的 AOT 友好 Cron 表达式解析与 occurrence 计算库。它提供规则的解析、验证、NextPreviousBetween,但不执行后台任务或维护调度状态。

dotnet add package Sparkdo.Crontab
using Sparkdo.Crontab;

var cron = Cron.Parse("*/15 * * * *");
var next = cron.Next(new DateTimeOffset(2026, 1, 1, 0, 7, 0, TimeSpan.Zero));

默认格式为“分 时 日 月 周”;可通过 CronFormat.SecondsYearsSecondsAndYears 使用秒和年份字段。字段支持通配符、列表、范围、步长、月份/星期英文名称,以及 LLWW#nLR

var workdayMorning = Cron.Parse("0 9 ? * MON-FRI");
var lastWeekday = Cron.Parse("0 0 LW * *");
var secondMonday = Cron.Parse("0 9 * * MON#2");

日与星期字段使用 AND 关系,星期 07 都表示周日。NextPreviousBetween 默认排除边界;通过 CronOptions.Boundary 可包含起点、终点或两端。

默认按 DateTimeOffset.Offset 计算固定 offset。需要本地时间或 DST 策略时,显式传入 TimeZoneInfo

var timeZone = TimeZoneInfo.FindSystemTimeZoneById("Asia/Shanghai");
var options = CronOptions.InTimeZone(timeZone);
var next = Cron.DailyAt(9).Next(DateTimeOffset.UtcNow, options);

CronOptions 可控制 DST 无效时间的跳过或前移,以及歧义时间的较早、较晚或双 occurrence 策略。外部输入使用 Cron.TryParseCron.IsValid 验证;Cron.Parse 的失败会抛出包含表达式、字段、位置和原因的 CronParseException

完整语法、时间语义、预设与验证命令见仓库 src/crontab/README.md

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.
  • net10.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Sparkdo.Crontab:

Package Downloads
Sparkdo.Scheduler

Sparkdo Scheduler runtime package and embedded source generator asset.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0-preview.2 55 7/20/2026
2.0.0-preview.1 50 7/18/2026