FluentCron 1.0.0

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

FluentCron

Stop writing cron expressions by hand. Build them with a fluent API instead.

// Instead of this:
var cron = "0 9-17 * * 1-5";

// Write this:
var cron = new CronBuilder()
    .AtMinute(0)
    .HourRange(9, 17)
    .DayOfWeekRange(DayOfWeek.Monday, DayOfWeek.Friday)
    .Build();

Installation

dotnet add package FluentCron

Why?

  • No more string errors - Type-safe cron expression building
  • Unix & Quartz formats - Works with everything (crontab, Hangfire, Quartz.NET)
  • Readable - Cron.Daily() beats "0 0 * * *" every time
  • Tested - 370 tests including integration tests with Quartz.NET and Hangfire

Quick Examples

using FluentCron;

// Every 5 minutes
new CronBuilder().EveryNMinutes(5).Build();
// → */5 * * * *

// Weekdays at 9 AM
Cron.Weekdays(9, 0);
// → 0 9 * * 1,2,3,4,5

// Last Friday of the month at 6 PM (Quartz)
new CronBuilder(CronFormat.Quartz)
    .AtSecond(0)
    .AtMinute(0)
    .AtHour(18)
    .OnLastWeekdayOfMonth(DayOfWeek.Friday)
    .Build();
// → 0 0 18 ? * 6L *

Common Patterns

Daily Tasks

Cron.Daily();                    // Midnight
Cron.DailyAt(14, 30);           // 2:30 PM

Weekly Tasks

Cron.Weekly();                              // Sunday at midnight
Cron.WeeklyOn(DayOfWeek.Friday, 17, 0);    // Friday at 5 PM

Business Hours

new CronBuilder()
    .EveryNMinutes(15)
    .HourRange(9, 17)
    .OnDayOfWeek(DayOfWeek.Monday, DayOfWeek.Tuesday, 
                 DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday)
    .Build();
// → */15 9-17 * * 1,2,3,4,5

Advanced Patterns

// Every 2 hours during business hours
new CronBuilder()
    .AtMinute(0)
    .HourRangeWithStep(9, 17, 2)
    .Build();
// → 0 9-17/2 * * *

// Second Tuesday of the month (Quartz)
new CronBuilder(CronFormat.Quartz)
    .AtSecond(0)
    .AtMinute(30)
    .AtHour(14)
    .OnNthWeekdayOfMonth(DayOfWeek.Tuesday, 2)
    .Build();
// → 0 30 14 ? * 3#2 *

Framework Integration

Hangfire

var cronExpression = new CronBuilder()
    .EveryNMinutes(5)
    .Build();

RecurringJob.AddOrUpdate(() => MyJob(), cronExpression);

Quartz.NET

var cronExpression = new CronBuilder(CronFormat.Quartz)
    .AtSecond(0)
    .EveryNMinutes(5)
    .Build();

var trigger = TriggerBuilder.Create()
    .WithCronSchedule(cronExpression)
    .Build();

NCrontab / System Cron

var cronExpression = new CronBuilder()
    .EveryNMinutes(5)
    .Build();

var schedule = CrontabSchedule.Parse(cronExpression);

API Overview

Time Fields

  • AtSecond(0, 30) - Specific seconds (Quartz only)
  • AtMinute(0, 15, 30, 45) - Specific minutes
  • AtHour(9, 17) - Specific hours
  • OnDayOfMonth(1, 15) - Specific days
  • InMonth(1, 6, 12) - Specific months
  • OnDayOfWeek(DayOfWeek.Monday) - Specific weekdays

Intervals

  • EveryNSeconds(10) - Every 10 seconds (Quartz only)
  • EveryNMinutes(5) - Every 5 minutes
  • EveryNHours(2) - Every 2 hours
  • EveryNDays(3) - Every 3 days

Ranges

  • MinuteRange(10, 40) - Minutes 10-40
  • HourRange(9, 17) - Hours 9-17
  • DayRange(1, 15) - Days 1-15
  • MonthRange(6, 8) - Months 6-8 (June-August)
  • DayOfWeekRange(DayOfWeek.Monday, DayOfWeek.Friday) - Monday-Friday

Ranges with Steps

  • MinuteRangeWithStep(10, 40, 5) - Every 5 minutes between 10-40
  • HourRangeWithStep(9, 17, 2) - Every 2 hours between 9 AM-5 PM

Quartz Special Characters

  • OnLastDayOfMonth() - Last day of month (L)
  • OnNearestWeekday(15) - Nearest weekday to the 15th (15W)
  • OnLastWeekdayOfMonth(DayOfWeek.Friday) - Last Friday (6L)
  • OnNthWeekdayOfMonth(DayOfWeek.Tuesday, 2) - 2nd Tuesday (3#2)
  • OnLastWeekday() - Last weekday of month (LW)

Formats

Unix (Default)

5 fields: minute hour day month weekday

new CronBuilder().EveryNMinutes(5).Build();
// → */5 * * * *

Quartz

7 fields: second minute hour day month weekday year

new CronBuilder(CronFormat.Quartz).EveryNMinutes(5).Build();
// → 0 */5 * * * ? *

Error Handling

FluentCron validates everything at build time:

// This will throw ArgumentOutOfRangeException
new CronBuilder().AtMinute(99).Build();  // Minutes must be 0-59

// This will throw InvalidOperationException
new CronBuilder(CronFormat.Unix).AtSecond(0).Build();  // Seconds only in Quartz

// This will throw ArgumentException
new CronBuilder().OnDayOfWeek().Build();  // Must specify at least one day

Testing

370 comprehensive tests including:

  • Unit tests for all features
  • Integration tests with Quartz.NET
  • Integration tests with Hangfire
  • Edge case and validation tests

Run tests:

dotnet test

License

MIT - see LICENSE file

Contributing

Issues and PRs welcome! This is a straightforward library - if you need a feature, open an issue first to discuss.


Built with ❤️ by Yigitalp Kilavuz

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.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

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
1.0.0 284 10/2/2025

Initial release of FluentCron v1.0.0

Features:
- Fluent API for building cron expressions with intuitive method chaining
- Dual format support: Unix (5-field) and Quartz (6-7 field) cron expressions
- 36+ builder methods including ranges, intervals, and special characters
- Predefined patterns: Daily, Weekly, Monthly, Yearly, Weekdays, Weekends
- Quartz-specific features: last day of month (L), nearest weekday (W), nth occurrence (#)
- Type-safe API with comprehensive input validation
- Full XML documentation for IntelliSense support

Quality:
- 393 tests with 100% pass rate
- 99.57% code coverage
- Integration tests with Quartz.NET and Hangfire
- Performance benchmarks included
- .NET 8.0 LTS target framework

For documentation and examples, visit: https://github.com/yigitalpkilavuz/FluentCron