{"id":17955287,"url":"https://github.com/atifaziz/ncrontab","last_synced_at":"2025-06-25T13:06:44.112Z","repository":{"id":50114286,"uuid":"41044247","full_name":"atifaziz/NCrontab","owner":"atifaziz","description":"Crontab for .NET","archived":false,"fork":false,"pushed_at":"2024-08-03T16:58:18.000Z","size":845,"stargazers_count":941,"open_issues_count":21,"forks_count":138,"subscribers_count":25,"default_branch":"master","last_synced_at":"2025-06-21T14:43:34.467Z","etag":null,"topics":["crontab","dotnet","hacktoberfest","schedule"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/atifaziz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-08-19T15:57:20.000Z","updated_at":"2025-06-16T09:42:03.000Z","dependencies_parsed_at":"2023-02-15T22:46:01.417Z","dependency_job_id":"2604464e-eedd-453c-abb5-a28dc3583cc8","html_url":"https://github.com/atifaziz/NCrontab","commit_stats":{"total_commits":187,"total_committers":6,"mean_commits":"31.166666666666668","dds":"0.048128342245989275","last_synced_commit":"9b68c8d1484ccd56a8f0bc1ce12e7270736f3493"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/atifaziz/NCrontab","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atifaziz%2FNCrontab","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atifaziz%2FNCrontab/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atifaziz%2FNCrontab/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atifaziz%2FNCrontab/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/atifaziz","download_url":"https://codeload.github.com/atifaziz/NCrontab/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atifaziz%2FNCrontab/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261879316,"owners_count":23223739,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["crontab","dotnet","hacktoberfest","schedule"],"created_at":"2024-10-29T10:25:47.009Z","updated_at":"2025-06-25T13:06:44.089Z","avatar_url":"https://github.com/atifaziz.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NCrontab: Crontab for .NET\n\n[![Build Status][build-badge]][builds]\n[![NuGet][nuget-badge]][nuget-pkg]\n\nNCrontab is a library written in C# targeting [.NET Standard Library][netstd]\n1.0 and that provides the following facilities:\n\n* Parsing of crontab expressions\n* Formatting of crontab expressions\n* Calculation of occurrences of time based on a crontab schedule\n\nThis library does not provide any scheduler or is not a scheduling facility like\ncron from Unix platforms. What it provides is parsing, formatting and an algorithm\nto produce occurrences of time based on a give schedule expressed in the crontab\nformat:\n\n    * * * * *\n    - - - - -\n    | | | | |\n    | | | | +----- day of week (0 - 6) (Sunday=0)\n    | | | +------- month (1 - 12)\n    | | +--------- day of month (1 - 31)\n    | +----------- hour (0 - 23)\n    +------------- min (0 - 59)\n\nor a six-part format that allows for seconds:\n\n    * * * * * *\n    - - - - - -\n    | | | | | |\n    | | | | | +--- day of week (0 - 6) (Sunday=0)\n    | | | | +----- month (1 - 12)\n    | | | +------- day of month (1 - 31)\n    | | +--------- hour (0 - 23)\n    | +----------- min (0 - 59)\n    +------------- sec (0 - 59)\n\nStar (`*`) in the value field above means all legal values as in parentheses for\nthat column. The value column can have a `*` or a list of elements separated by\ncommas. An element is either a number in the ranges shown above or two numbers in\nthe range separated by a hyphen (meaning an inclusive range). For more, see\n[CrontabExpression].\n\nThe default format parsed by `CrontabSchedule.Parse` is the five-part cron\nformat. In order to use the six-part format that includes seconds, pass a\n`CrontabSchedule.ParseOptions` to `Parse` with `IncludingSeconds` set to\n`true`. For example:\n\n```csharp\nvar s = CrontabSchedule.Parse(\"0,30 * * * * *\",\n                              new CrontabSchedule.ParseOptions\n                              {\n                                  IncludingSeconds = true\n                              });\n```\n\nBelow is an example in [IronPython][ipy] of how to use `CrontabSchedule` class\nfrom NCrontab to generate occurrences of the schedule `0 12 * */2 Mon`\n(meaning, *12:00 PM on Monday of every other month, starting with January*)\nthroughout the year 2000:\n\n    IronPython 1.1 (1.1) on .NET 2.0.50727.1434\n    Copyright (c) Microsoft Corporation. All rights reserved.\n    \u003e\u003e\u003e import clr\n    \u003e\u003e\u003e clr.AddReferenceToFileAndPath(r'C:\\NCrontab\\bin\\Release\\NCrontab.dll')\n    \u003e\u003e\u003e from System import DateTime\n    \u003e\u003e\u003e from NCrontab import CrontabSchedule\n    \u003e\u003e\u003e s = CrontabSchedule.Parse('0 12 * */2 Mon')\n    \u003e\u003e\u003e start = DateTime(2000, 1, 1)\n    \u003e\u003e\u003e end = start.AddYears(1)\n    \u003e\u003e\u003e occurrences = s.GetNextOccurrences(start, end)\n    \u003e\u003e\u003e print '\\n'.join([t.ToString('ddd, dd MMM yyyy HH:mm') for t in occurrences])\n    Mon, 03 Jan 2000 12:00\n    Mon, 10 Jan 2000 12:00\n    Mon, 17 Jan 2000 12:00\n    Mon, 24 Jan 2000 12:00\n    Mon, 31 Jan 2000 12:00\n    Mon, 06 Mar 2000 12:00\n    Mon, 13 Mar 2000 12:00\n    Mon, 20 Mar 2000 12:00\n    Mon, 27 Mar 2000 12:00\n    Mon, 01 May 2000 12:00\n    Mon, 08 May 2000 12:00\n    Mon, 15 May 2000 12:00\n    Mon, 22 May 2000 12:00\n    Mon, 29 May 2000 12:00\n    Mon, 03 Jul 2000 12:00\n    Mon, 10 Jul 2000 12:00\n    Mon, 17 Jul 2000 12:00\n    Mon, 24 Jul 2000 12:00\n    Mon, 31 Jul 2000 12:00\n    Mon, 04 Sep 2000 12:00\n    Mon, 11 Sep 2000 12:00\n    Mon, 18 Sep 2000 12:00\n    Mon, 25 Sep 2000 12:00\n    Mon, 06 Nov 2000 12:00\n    Mon, 13 Nov 2000 12:00\n    Mon, 20 Nov 2000 12:00\n    Mon, 27 Nov 2000 12:00\n\nBelow is the same example in [F#][f#] Interactive (`fsi.exe`):\n\n    Microsoft (R) F# 2.0 Interactive build 4.0.40219.1\n    Copyright (c) Microsoft Corporation. All Rights Reserved.\n\n    For help type #help;;\n\n    \u003e #r \"NCrontab.dll\"\n    -\n    - open NCrontab\n    - open System\n    -\n    - let schedule = CrontabSchedule.Parse(\"0 12 * */2 Mon\")\n    - let startDate = DateTime(2000, 1, 1)\n    - let endDate = startDate.AddYears(1)\n    -\n    - let occurrences = schedule.GetNextOccurrences(startDate, endDate)\n    - occurrences |\u003e Seq.map (fun t -\u003e t.ToString(\"ddd, dd MMM yyy HH:mm\"))\n    -             |\u003e String.concat \"\\n\"\n    -             |\u003e printfn \"%s\";;\n\n    --\u003e Referenced 'C:\\NCrontab\\bin\\Release\\NCrontab.dll'\n\n    Mon, 03 Jan 2000 12:00\n    Mon, 10 Jan 2000 12:00\n    Mon, 17 Jan 2000 12:00\n    Mon, 24 Jan 2000 12:00\n    Mon, 31 Jan 2000 12:00\n    Mon, 06 Mar 2000 12:00\n    Mon, 13 Mar 2000 12:00\n    Mon, 20 Mar 2000 12:00\n    Mon, 27 Mar 2000 12:00\n    Mon, 01 May 2000 12:00\n    Mon, 08 May 2000 12:00\n    Mon, 15 May 2000 12:00\n    Mon, 22 May 2000 12:00\n    Mon, 29 May 2000 12:00\n    Mon, 03 Jul 2000 12:00\n    Mon, 10 Jul 2000 12:00\n    Mon, 17 Jul 2000 12:00\n    Mon, 24 Jul 2000 12:00\n    Mon, 31 Jul 2000 12:00\n    Mon, 04 Sep 2000 12:00\n    Mon, 11 Sep 2000 12:00\n    Mon, 18 Sep 2000 12:00\n    Mon, 25 Sep 2000 12:00\n    Mon, 06 Nov 2000 12:00\n    Mon, 13 Nov 2000 12:00\n    Mon, 20 Nov 2000 12:00\n    Mon, 27 Nov 2000 12:00\n\nBelow is the same example in C# Interactive (`csi.exe`):\n\n    Microsoft (R) Visual C# Interactive Compiler version 1.2.0.60317\n    Copyright (C) Microsoft Corporation. All rights reserved.\n\n    Type \"#help\" for more information.\n    \u003e #r \"NCrontab.dll\"\n    \u003e using NCrontab;\n    \u003e var s = CrontabSchedule.Parse(\"0 12 * */2 Mon\");\n    \u003e var start = new DateTime(2000, 1, 1);\n    \u003e var end = start.AddYears(1);\n    \u003e var occurrences = s.GetNextOccurrences(start, end);\n    \u003e Console.WriteLine(string.Join(Environment.NewLine,\n    .     from t in occurrences\n    .     select $\"{t:ddd, dd MMM yyyy HH:mm}\"));\n    Mon, 03 Jan 2000 12:00\n    Mon, 10 Jan 2000 12:00\n    Mon, 17 Jan 2000 12:00\n    Mon, 24 Jan 2000 12:00\n    Mon, 31 Jan 2000 12:00\n    Mon, 06 Mar 2000 12:00\n    Mon, 13 Mar 2000 12:00\n    Mon, 20 Mar 2000 12:00\n    Mon, 27 Mar 2000 12:00\n    Mon, 01 May 2000 12:00\n    Mon, 08 May 2000 12:00\n    Mon, 15 May 2000 12:00\n    Mon, 22 May 2000 12:00\n    Mon, 29 May 2000 12:00\n    Mon, 03 Jul 2000 12:00\n    Mon, 10 Jul 2000 12:00\n    Mon, 17 Jul 2000 12:00\n    Mon, 24 Jul 2000 12:00\n    Mon, 31 Jul 2000 12:00\n    Mon, 04 Sep 2000 12:00\n    Mon, 11 Sep 2000 12:00\n    Mon, 18 Sep 2000 12:00\n    Mon, 25 Sep 2000 12:00\n    Mon, 06 Nov 2000 12:00\n    Mon, 13 Nov 2000 12:00\n    Mon, 20 Nov 2000 12:00\n    Mon, 27 Nov 2000 12:00\n\nBelow is the same example in C# using [`dotnet-script`][dotnet-script]:\n\n    \u003e #r \"nuget:NCrontab\"\n    \u003e using NCrontab;\n    \u003e var s = CrontabSchedule.Parse(\"0 12 * */2 Mon\");\n    \u003e var start = new DateTime(2000, 1, 1);\n    \u003e var end = start.AddYears(1);\n    \u003e var occurrences = s.GetNextOccurrences(start, end);\n    \u003e Console.WriteLine(string.Join(Environment.NewLine,\n    *     from t in occurrences\n    *     select $\"{t:ddd, dd MMM yyyy HH:mm}\"));\n    Mon, 03 Jan 2000 12:00\n    Mon, 10 Jan 2000 12:00\n    Mon, 17 Jan 2000 12:00\n    Mon, 24 Jan 2000 12:00\n    Mon, 31 Jan 2000 12:00\n    Mon, 06 Mar 2000 12:00\n    Mon, 13 Mar 2000 12:00\n    Mon, 20 Mar 2000 12:00\n    Mon, 27 Mar 2000 12:00\n    Mon, 01 May 2000 12:00\n    Mon, 08 May 2000 12:00\n    Mon, 15 May 2000 12:00\n    Mon, 22 May 2000 12:00\n    Mon, 29 May 2000 12:00\n    Mon, 03 Jul 2000 12:00\n    Mon, 10 Jul 2000 12:00\n    Mon, 17 Jul 2000 12:00\n    Mon, 24 Jul 2000 12:00\n    Mon, 31 Jul 2000 12:00\n    Mon, 04 Sept 2000 12:00\n    Mon, 11 Sept 2000 12:00\n    Mon, 18 Sept 2000 12:00\n    Mon, 25 Sept 2000 12:00\n    Mon, 06 Nov 2000 12:00\n    Mon, 13 Nov 2000 12:00\n    Mon, 20 Nov 2000 12:00\n    Mon, 27 Nov 2000 12:00\n\nSome complex schedules cannot be expressed in a single crontab expression so\nNCrontab can produce _distinct occurrences_ given a sequence of\n`CrontabSchedule` instances. In the C# example below, two schedules are merged\nto produce a single set of occurrences over a week. The first schedule occurs\nevery 6 hours on weekdays while the second occurs every 12 hours on weekends.\n\n    Microsoft (R) Visual C# Interactive Compiler version 1.2.0.60317\n    Copyright (C) Microsoft Corporation. All rights reserved.\n\n    Type \"#help\" for more information.\n    \u003e using NCrontab;\n    \u003e var s1 = CrontabSchedule.Parse(\"0 */6 * * Mon-Fri\");\n    \u003e var s2 = CrontabSchedule.Parse(\"0 */12 * * Sat,Sun\");\n    \u003e var s = new[] { s1, s2 };\n    \u003e var start = new DateTime(2000, 1, 1);\n    \u003e var end = start.AddDays(7);\n    \u003e var occurrences = s.GetNextOccurrences(start, end);\n    \u003e // `Sat, 01 Jan 2000 10:00` won't appear because `start` is exclusive\n    \u003e Console.WriteLine(string.Join(Environment.NewLine,\n    .     from t in occurrences\n    .     select $\"{t:ddd, dd MMM yyyy HH:mm}\"));\n    Sat, 01 Jan 2000 12:00\n    Sun, 02 Jan 2000 00:00\n    Sun, 02 Jan 2000 12:00\n    Mon, 03 Jan 2000 00:00\n    Mon, 03 Jan 2000 06:00\n    Mon, 03 Jan 2000 12:00\n    Mon, 03 Jan 2000 18:00\n    Tue, 04 Jan 2000 00:00\n    Tue, 04 Jan 2000 06:00\n    Tue, 04 Jan 2000 12:00\n    Tue, 04 Jan 2000 18:00\n    Wed, 05 Jan 2000 00:00\n    Wed, 05 Jan 2000 06:00\n    Wed, 05 Jan 2000 12:00\n    Wed, 05 Jan 2000 18:00\n    Thu, 06 Jan 2000 00:00\n    Thu, 06 Jan 2000 06:00\n    Thu, 06 Jan 2000 12:00\n    Thu, 06 Jan 2000 18:00\n    Fri, 07 Jan 2000 00:00\n    Fri, 07 Jan 2000 06:00\n    Fri, 07 Jan 2000 12:00\n    Fri, 07 Jan 2000 18:00\n\nIf one or more schedules produce the same occurrence then only one of them\nif returned.\n\n## Merging Schedules\n\nNCrontab can merge the timeline of one or more schedules. This can sometimes\ncome handy when it's impossible to express a schedule with a single crontab\nexpression like _every 6 hours from 9 AM to 5 PM, on weekdays, but at noon on\nweekends_. By breaking it up into two schedules:\n\n- `0 12 * * Sat-Sun`: at noon on weekends\n- `0 9-17/6 * * Mon-Fri`: every 6 hours from 9 AM to 5 PM on weekdays\n\nyou can merge them to produce a single timeline:\n\n```csharp\nusing System;\nusing NCrontab;\n\nvar start = new DateTime(2000, 1, 1);\nvar end = start.AddYears(1);\nvar schedules = new[]\n{\n    CrontabSchedule.Parse(\"0 12 * * Sat-Sun\"),\n    CrontabSchedule.Parse(\"0 9-17/6 * * Mon-Fri\")\n};\nvar occurrences = schedules.GetNextOccurrences(start, end);\nConsole.WriteLine(string.Join(Environment.NewLine,\n                              from t in occurrences\n                              select $\"{t:ddd, dd MMM yyyy HH:mm}\"));\n```\n\nThe output from a run will:\n\n    Sat, 01 Jan 2000 12:00\n    Sun, 02 Jan 2000 12:00\n    Mon, 03 Jan 2000 09:00\n    Mon, 03 Jan 2000 12:00\n    Mon, 03 Jan 2000 15:00\n    Tue, 04 Jan 2000 09:00\n    Tue, 04 Jan 2000 12:00\n    Tue, 04 Jan 2000 15:00\n    Wed, 05 Jan 2000 09:00\n    Wed, 05 Jan 2000 12:00\n    Wed, 05 Jan 2000 15:00\n    Thu, 06 Jan 2000 09:00\n    Thu, 06 Jan 2000 12:00\n    Thu, 06 Jan 2000 15:00\n    Fri, 07 Jan 2000 09:00\n    Fri, 07 Jan 2000 12:00\n    Fri, 07 Jan 2000 15:00\n    Sat, 08 Jan 2000 12:00\n    Sun, 09 Jan 2000 12:00\n    ...\n\nIf two or more schedules produce the same occurrence then only one of them\nis returned.\n\n---\n\nThis product includes software developed by the [OpenSymphony Group].\n\n\n  [CrontabExpression]: https://github.com/atifaziz/NCrontab/wiki/Crontab-Expression\n  [ipy]: http://en.wikipedia.org/wiki/IronPython\n  [f#]: http://msdn.microsoft.com/en-us/fsharp/cc742182\n  [build-badge]: https://img.shields.io/appveyor/ci/raboof/ncrontab/master.svg\n  [nuget-badge]: https://img.shields.io/nuget/v/ncrontab.svg\n  [nuget-pkg]: https://www.nuget.org/packages/ncrontab\n  [builds]: https://ci.appveyor.com/project/raboof/ncrontab\n  [netstd]: https://docs.microsoft.com/en-us/dotnet/articles/standard/library\n  [dotnet-script]: https://github.com/dotnet-script/dotnet-script\n  [OpenSymphony Group]: http://www.opensymphony.com/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatifaziz%2Fncrontab","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fatifaziz%2Fncrontab","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatifaziz%2Fncrontab/lists"}