HangfireIO / Cronos
A fully-featured .NET library for working with Cron expressions. Built with time zones in mind and intuitively handles daylight saving time transitions
AI Architecture Analysis
This repository is indexed by RepoMind. By analyzing HangfireIO/Cronos in our AI interface, you can instantly generate complete architecture diagrams, visualize control flows, and perform automated security audits across the entire codebase.
Our Agentic Context Augmented Generation (Agentic CAG) engine loads full source files into context on-demand, avoiding the fragmentation of traditional RAG systems. Ask questions about the architecture, dependencies, or specific features to see it in action.
Repository Overview (README excerpt)
Crawler viewCronos Cronos is a .NET library for parsing Cron expressions and calculating next occurrences. It was designed with time zones in mind, and intuitively handles Daylight saving time (also known as Summer time) transitions as in *nix Cron. *Please note this library doesn't include any task/job scheduler, it only works with Cron expressions.* • Supports standard Cron format with optional seconds. • Supports non-standard characters like , , and their combinations. • Supports reversed ranges, like (equivalent to ) or (equivalent to ). • Supports time zones, and performs all the date/time conversions for you. • Does not skip occurrences, when the clock jumps forward to Daylight saving time (known as Summer time). • Does not skip interval-based occurrences, when the clock jumps backward from Summer time. • Does not retry non-interval based occurrences, when the clock jumps backward from Summer time. • Contains 1000+ unit tests to ensure everything is working correctly. Compatibility This section explains how Cron expressions should be converted, when moving to Cronos. Library | Comments --- | --- Vixie Cron | When both day-of-month and day-of-week are specified, Cronos uses AND operator for matching (Vixie Cron uses OR operator for backward compatibility). Quartz.NET | Cronos uses different, but more intuitive Daylight saving time handling logic (as in Vixie Cron). Full month names such as aren't supported. Day-of-week field in Cronos has different values, and stand for Sunday, for Monday, etc. (as in Vixie Cron). Year field is not supported. NCrontab | Compatible CronNET | Compatible Installation Cronos is distributed as a NuGet package, you can install it from the official NuGet Gallery. Please use the following command to install it using the NuGet Package Manager Console window. Usage We've tried to do our best to make Cronos API as simple and predictable in corner cases as possible. So you can only use with specified (for example, ), or classes to calculate next occurrences. You **can not use** local objects (such as ), because this may lead to ambiguity during DST transitions, and an exception will be thrown if you attempt to use them. To calculate the next occurrence, you need to create an instance of the class, and call its method. To learn about Cron format, please refer to the next section. The will contain the next occurrence in UTC, *after the given time*, or value when it is unreachable (for example, Feb 30). If an invalid Cron expression is given, the exception is thrown. Working with time zones It is possible to specify a time zone directly, in this case you should pass with flag, or use class, that's is smart enough to always point to an exact, non-ambiguous instant. If you passed a object, resulting time will be in UTC. If you used , resulting object will contain the **correct offset**, so don't forget to use it especially during DST transitions (see below). Working with local time If you just want to make all the calculations using local time, you'll have to use the class, because as I've said earlier, objects may be ambiguous during Summer time transitions. You can get the resulting local time, using the property. Adding seconds to an expression If you want to specify seconds, use another overload of the method and specify the argument as below: Getting occurrences within a range You can also get occurrences within a fixed date/time range using the method. By default, the argument will be included when matched, and argument will be excluded. However, you can configure that behavior. There are different overloads for this method to support arguments or time zones. Cron format Cron expression is a mask to define fixed times, dates and intervals. The mask consists of second (optional), minute, hour, day-of-month, month and day-of-week fields. All of the fields allow you to specify multiple values, and any given date/time will satisfy the specified Cron expression, if all the fields contain a matching value. Allowed values Allowed special characters Comment ┌───────────── second (optional) 0-59 * , - / │ ┌───────────── minute 0-59 * , - / │ │ ┌───────────── hour 0-23 * , - / │ │ │ ┌───────────── day of month 1-31 * , - / L W ? │ │ │ │ ┌───────────── month 1-12 or JAN-DEC * , - / │ │ │ │ │ ┌───────────── day of week 0-6 or SUN-SAT * , - / # L ? Both 0 and 7 means SUN │ │ │ │ │ │ • * * * * * Base characters In all fields you can use number, to mark field as *any value*, to specify ranges of values. Reversed ranges like (equivalent to ) are also supported. It's possible to define **step** combining with , numbers and ranges. For example, in minute field describes *every 5 minute* and in day-of-month field – *every 3 days from the 1st to the 15th*. Pay attention that is just equivalent to and in minute field doesn't literally mean *every 24 minutes* it means *every 0,24,48 minute*. Concatinate values and ranges by . Comma works like operator. So is equivalent to . In month and day-of-week fields, you can use names of months or days of weeks abbreviated to first three letters ( or ) instead of their numeric values. Full names like or **aren't supported**. For day of week field, both and stays for Sunday, 1 for Monday. | Expression | Description | |----------------------|---------------------------------------------------------------------------------------| | | Every minute | | | At midnight, on day 1 of every month | | | Every 5 minutes | | | Every 2 minute from 1:00 AM to 01:15 AM and from 1:45 AM to 1:59 AM and at 1:30 AM | | | At 00:00, Monday through Friday | Special characters Most expressions you can describe using base characters. If you want to deal with more complex cases like *the last day of month* or *the 2nd Saturday* use special characters: ** ** stands for "last". When used in the day-of-week field, it allows you to specify constructs such as *the last Friday* ( or ). In the day-of-month field, it specifies the last day of the…