Skip to content
Projets

À propos

CronCraft is a lightweight, developer-friendly .NET SDK that converts cron expressions into human-readable strings, with support for localization, formatting, and time zone awareness — no configuration files required.

Outils de développement

Comment ces chiffres sont mesurés

What you can do

  • 🔄 Converts standard or Quartz cron expressions to plain language
  • 🌍 Localized day-of-week formatting (short, full, single, or custom)
  • 🕘 Time zone adjustment (optional)
  • 🔧 Fully configurable via CronSettings object

Progression mesurée des étoiles

in 24h
0
in 7 days
0
in 15 days
0
in 1 month
Historique en cours

Variations nettes sur des périodes qui se chevauchent, pas des totaux quotidiens. Les mesures absentes restent vides. Les étoiles indiquent l’intérêt, pas la qualité.

README.md

Original

🕒 CronCraft

CronCraft is a lightweight, developer-friendly .NET SDK that converts cron expressions into human-readable strings — with support for localization, formatting, and time zone awareness — no configuration files required.


Documentation · Cron playground

🤔 Why CronCraft?

CronCraft is designed for clarity, speed, and minimal setup.

Whether you're building a web app, a CLI tool, a Windows Service, or a background worker — just create a CronSettings object, and you're good to go.

❝ No dependency injection required. No appsettings. Just clean, functional cron parsing. ❞


✨ Features

  • 🔄 Converts standard or Quartz cron expressions to plain language
  • 🌍 Localized day-of-week formatting (short, full, single, or custom)
  • 🕘 Time zone adjustment (optional)
  • 🔧 Fully configurable via CronSettings object
  • 💉 Optional dependency injection registration with AddCronCraft
  • 📦 Lightweight, zero-dependency core logic
  • 🟢 Node.js package for common Unix cron schedules

📦 Installation

dotnet add package CronCraft

Terminal tool

Run croncraft next "0 9 * * MON-FRI" --count 5 to preview upcoming runs. See the tool guide for installation, the explain and validate commands, and JSON output.

🛠️ Usage Example

using CronCraft.Models;
using CronCraft.Extensions;

string cronExpression = "0 0 * * *"; // Every day at midnight

var settings = new CronSettings
{
    Language = "en",
    DayNameFormat = "short",
    TimeFormat = "HH:mm" // Optional: 24-hour output (default: "hh:mm tt")
};

// Without timezone
string humanReadable = cronExpression.ToHumanReadable(settings);
Console.WriteLine("🔁 CronCraft Expression Translator");
Console.WriteLine("-----------------------------------");
Console.WriteLine($"🧾 Cron Expression:   {cronExpression}");
Console.WriteLine($"📖 Human Readable:    {humanReadable}");
Console.WriteLine("-----------------------------------");
Console.WriteLine("Press Enter to exit...");

// With TimeZone
TimeZoneInfo timeZone = TimeZoneInfo.FindSystemTimeZoneById("W. Central Africa Standard Time");
humanReadable = cronExpression.ToHumanReadable(settings, timeZone);
Console.WriteLine($"📖 Human Readable (Local TZ): {humanReadable}");

Console.ReadLine();

Dependency Injection

For ASP.NET Core and generic host applications, register CronCraft through IServiceCollection:

using CronCraft.Extensions;

builder.Services.AddCronCraft(settings =>
{
    settings.Language = "en";
    settings.DayNameFormat = "short";
});

Then inject CronCraftService where it is needed:

public class MyScheduler(CronCraftService cronCraft)
{
    public string Describe(string expression) => cronCraft.Convert(expression);
}

Expected Output:

🔁 CronCraft Expression Translator
-----------------------------------
🧾 Cron Expression:   0 0 * * *
📖 Human Readable:    Every day at 12:00 AM
-----------------------------------
📖 Human Readable (Local TZ): Every day at 01:00 AM
Press Enter to exit...

✅ Validation and Non-Throwing Conversion

ToHumanReadable continues to throw ArgumentException, InvalidCronExpressionException, or timezone exceptions when invalid input is exceptional:

try
{
    string description = cronExpression.ToHumanReadable(settings);
}
catch (InvalidCronExpressionException ex)
{
    Console.WriteLine(ex.ValidationError.Code);
}

Interactive applications can use the non-throwing API instead:

if (cronExpression.TryToHumanReadable(
        settings,
        out var description,
        out var error))
{
    Console.WriteLine(description);
}
else
{
    Console.WriteLine($"{error!.Code}: {error.Message}");
}

bool valid = cronExpression.IsValid(settings);
bool detailed = cronExpression.TryValidate(out var validationError, settings);

Dependency-injection users can call TryConvert, TryValidate, and IsValid on CronCraftService.

Stable error codes are available through CronValidationErrorCodes:

Code Meaning
null_expression The expression reference is null
empty_expression The expression is empty or whitespace
invalid_part_count The expression has an unsupported field count
invalid_field_value A cron field contains an invalid value
invalid_range A range is malformed, out of bounds, or reversed
unsupported_syntax CronCraft does not support the supplied syntax
invalid_time_zone The configured timezone is unavailable
invalid_settings Another formatting or mapping setting is invalid

Preview upcoming runs

Use CronSchedule to see when a cron expression is due to run. The timezone determines which local dates and times the expression matches.

using CronCraft;

var timeZone = TimeZoneInfo.FindSystemTimeZoneById("Europe/London");
var from = new DateTimeOffset(2026, 3, 27, 9, 0, 0, TimeSpan.Zero);
var runs = CronSchedule.GetNextOccurrences("0 9 * * MON-FRI", from, 5, timeZone);
// First result is 2026-03-30 09:00 +01:00.
  • GetNextOccurrence returns one match. GetNextOccurrences returns up to the requested number. Both search strictly after the starting instant and default to UTC. Results are ordered by instant, without duplicates, and retain their offsets in the schedule timezone.
  • A skipped local time produces no run. A repeated local time produces both matching instants, with their distinct offsets.
  • Five-field Unix expressions and six- or seven-field Quartz expressions support lists, ranges, steps, and named months and weekdays. Unix uses 0 or 7 for Sunday. Quartz preview uses 1 for Sunday through 7 for Saturday and also accepts 0 as Sunday. ToHumanReadable uses legacy zero-based numbering for plain numeric weekdays. Use a name such as MON when sharing expressions between the two APIs. Quartz day modifiers include L, LW, nW, nL, and n#k. If the day in nW exceeds the month length, the search starts at month end and stays within that month. A day field set to * or ? defers to the other day field. When both are restricted, either can match. In Unix, a leading wildcard in a day field, including a stepped wildcard, requires both day fields to match.
  • Periodic aliases such as @daily work. @reboot has no scheduled instant. A schedule with no future match throws InvalidCronExpressionException with the no_future_occurrence code. If a finite schedule has some matches but fewer than requested, the API returns the remaining matches.

Preview adds no package dependencies.

English schedules to cron

EnglishCronParser.TryParse converts common English schedules into five-field Unix cron. Matching is case-insensitive and allows extra whitespace between words.

using CronCraft;

if (EnglishCronParser.TryParse("weekdays at 18:00", out var cron, out var error))
    Console.WriteLine(cron); // 0 18 * * 1-5
else
    Console.WriteLine(error.Message);

Supported phrases include every 15 minutes, every 6 hours, daily at 9:30 AM, every day at 07:00, weekends at 18:00, and every Monday at 9am. Use a 24-hour time with minutes or a time with AM/PM. Minute intervals must divide into 60 and hour intervals into 24. Unsupported phrases, ambiguous times such as daily at 9, and timezone suffixes return a structured validation error.

🔧 Supported Day Name Formats

  • full: e.g. "Sunday"
  • short: e.g. "Sun"
  • single: e.g. "S"
  • custom: fully user-defined via Dictionary<string, string>

📅 Named Weekdays and Months

Weekday and month abbreviations are case-insensitive and work in individual, list, and range expressions:

"0 9 * JAN MON".ToHumanReadable(settings);
// Every Mon in January at 09:00 AM

"0 9 * * MON-FRI".ToHumanReadable(settings);
// Every Mon through Fri at 09:00 AM

"0 0 1 JAN,JUL *".ToHumanReadable(settings);
// Every year on January 1st and July 1st at 12:00 AM

Supported weekday names are SUN through SAT; supported month names are JAN through DEC.


⚡ Cron Aliases

Common Unix cron aliases can be used instead of five-part expressions:

"@hourly".ToHumanReadable(settings);  // Every hour
"@daily".ToHumanReadable(settings);   // Every day at 12:00 AM
"@weekly".ToHumanReadable(settings);  // Every Sun at 12:00 AM
"@monthly".ToHumanReadable(settings); // Every month on the 1st at 12:00 AM
"@yearly".ToHumanReadable(settings);  // Every year on January 1st at 12:00 AM
"@reboot".ToHumanReadable(settings);  // At system reboot

Aliases are case-insensitive and produce localized descriptions using the selected CronSettings.Language.


⏱️ Quartz Seconds and Years

Quartz expressions may contain six fields (including seconds) or seven fields (including an optional year):

"*/10 * * * * ?".ToHumanReadable(settings);
// Every 10 seconds

"30 15 10 * * ?".ToHumanReadable(settings);
// Every day at 10:15:30 AM

"0 0 12 * * ? 2027-2029".ToHumanReadable(settings);
// Every day at 12:00 PM in 2027 through 2029

Seconds support fixed values, wildcards, steps, lists, and ranges from 0 to 59. A non-zero fixed second is added to the rendered time even when TimeFormat omits ss; formats that already contain seconds are preserved.

Years support values, steps, lists, and ranges from 1970 to 2099. A * year remains unrestricted and is omitted from the description. Five-field Unix cron expressions keep their existing behavior.


🌐 Languages Supported

  • English (en)
  • Spanish (es)
  • French (fr)
  • German (de)
  • Portuguese (pt)
  • Italian (it)
  • Dutch (nl)
  • Simplified Chinese (zh)
  • Japanese (ja)
  • Hindi (hi)
  • Korean (ko)
  • Turkish (tr)
  • Arabic (ar)
  • Russian (ru)
  • Polish (pl)
  • Easily extendable via custom mappings

Localized descriptions use language-specific ordinals, conjunctions, ranges, and singular forms:

var french = new CronSettings { Language = "fr", DayNameFormat = "short" };

string description = "0 9 * * 1,3,5".ToHumanReadable(french);
// Chaque lun, mer et ven à 09:00 AM
var hindi = new CronSettings { Language = "hi", DayNameFormat = "full" };

string description = "0 9 * * MON-FRI".ToHumanReadable(hindi);
// सोमवार से शुक्रवार तक हर दिन 09:00 बजे

Hindi descriptions use Devanagari text, Western digits (0–9), and a 24-hour clock (HH:mm) by default. Technical loanwords such as सेकंड (second) and सिस्टम (system) are written in Devanagari. Use standard timezone identifiers such as Asia/Kolkata with TimeZone.

var korean = new CronSettings { Language = "ko", DayNameFormat = "full" };

string description = "0 9 * * MON-FRI".ToHumanReadable(korean);
// 매주 월요일부터 금요일까지 09:00에

Korean output uses a 24-hour clock (HH:mm) and numeric month names such as 3월. Both short and single use one-character weekday names such as 월.

var turkish = new CronSettings { Language = "tr", DayNameFormat = "full" };

string description = "0 9 * * MON-FRI".ToHumanReadable(turkish);
// Pazartesi ile Cuma arasında her gün saat 09:00'da

Turkish output defaults to a 24-hour clock (HH:mm), uses Turkish month names such as Nisan, and applies vowel harmony to suffixes on clock values.

var arabic = new CronSettings { Language = "ar", DayNameFormat = "full" };

string description = "0 9 * * MON-FRI".ToHumanReadable(arabic);
// كل يوم من الاثنين إلى الجمعة عند الساعة 09:00

Arabic uses Modern Standard Arabic, Gregorian month names, Western digits (0–9), and 24-hour time (HH:mm). In HTML, render the description in an element with lang="ar" dir="rtl". Display raw cron expressions in a separate left-to-right element. CronCraft returns text in logical order and does not insert hidden direction controls.

var russian = new CronSettings { Language = "ru", DayNameFormat = "full" };

string description = "0 9 * * MON-FRI".ToHumanReadable(russian);
// Ежедневно с понедельника по пятницу в 09:00

Russian defaults to a 24-hour clock (HH:mm). Full weekday names and month names are inflected in descriptions. The single-letter weekday labels are distinct, for example П for Monday and Я for Friday.

var polish = new CronSettings { Language = "pl", DayNameFormat = "full" };

string description = "0 9 * * MON-FRI".ToHumanReadable(polish);
// Codziennie od poniedziałku do piątku o 09:00

Polish defaults to a 24-hour clock (HH:mm). Descriptions use inflected weekday and month names and Polish plural forms. Single-letter weekday labels are distinct, including P for Monday and Ą for Friday.


Custom localization providers

Supply your own language pack or override phrases in a built-in language. See the custom localization guide for direct and dependency-injection examples.

🧑‍💻 Author

Esanju Babatunde
GitHub · LinkedIn


📊 Performance Benchmarks

CronCraft includes a BenchmarkDotNet project to measure parsing performance across expression types and languages.

Run the benchmarks:

cd CronCraft.Benchmarks
dotnet run -c Release -- --filter *

Sample results (Apple M-series, .NET 8):

Benchmark Mean Allocated
Simple (*/5 * * * *) ~1 µs minimal
With day list (0 */2 * * 1,2,3,4,5) ~2 µs minimal
Quartz 6-part ~1.5 µs minimal
With timezone ~2 µs minimal
Spanish ~1.5 µs minimal

Tip: add --filter *Simple* to run a single benchmark by name.


🤝 Contributing

Contributions are welcome! If you'd like to:

  • Fix a bug
  • Improve performance
  • Add support for a new language
  • Refactor or improve documentation

Feel free to open a Pull Request or start a Discussion.

Before contributing:

  1. Fork the repo
  2. Create your feature branch (git checkout -b feature/your-feature)
  3. Commit your changes (git commit -m 'Add your message')
  4. Push to the branch (git push origin feature/your-feature)
  5. Open a pull request 🚀

If you're not sure where to start, check the issues or the CONTRIBUTING guide for a full list of open tasks.

Let's make cron expressions human again! ❤️


📄 License

This project is licensed under the MIT License.
See the LICENSE file for details.

Explorer des projets similaires

Chargement…