• Stars
    star
    823
  • Rank 55,417 (Top 2 %)
  • Language
    C#
  • License
    Apache License 2.0
  • Created over 9 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Crontab for .NET

NCrontab: Crontab for .NET

Build Status NuGet

NCrontab is a library written in C# targeting .NET Standard Library 1.0 and that provides the following facilities:

  • Parsing of crontab expressions
  • Formatting of crontab expressions
  • Calculation of occurrences of time based on a crontab schedule

This library does not provide any scheduler or is not a scheduling facility like cron from Unix platforms. What it provides is parsing, formatting and an algorithm to produce occurrences of time based on a give schedule expressed in the crontab format:

* * * * *
- - - - -
| | | | |
| | | | +----- day of week (0 - 6) (Sunday=0)
| | | +------- month (1 - 12)
| | +--------- day of month (1 - 31)
| +----------- hour (0 - 23)
+------------- min (0 - 59)

or a six-part format that allows for seconds:

* * * * * *
- - - - - -
| | | | | |
| | | | | +--- day of week (0 - 6) (Sunday=0)
| | | | +----- month (1 - 12)
| | | +------- day of month (1 - 31)
| | +--------- hour (0 - 23)
| +----------- min (0 - 59)
+------------- sec (0 - 59)

Star (*) in the value field above means all legal values as in parentheses for that column. The value column can have a * or a list of elements separated by commas. An element is either a number in the ranges shown above or two numbers in the range separated by a hyphen (meaning an inclusive range). For more, see CrontabExpression.

Below is an example in IronPython of how to use CrontabSchedule class from NCrontab to generate occurrences of the schedule 0 12 * */2 Mon (meaning, 12:00 PM on Monday of every other month, starting with January) throughout the year 2000:

IronPython 1.1 (1.1) on .NET 2.0.50727.1434
Copyright (c) Microsoft Corporation. All rights reserved.
>>> import clr
>>> clr.AddReferenceToFileAndPath(r'C:\NCrontab\bin\Release\NCrontab.dll')
>>> from System import DateTime
>>> from NCrontab import CrontabSchedule
>>> s = CrontabSchedule.Parse('0 12 * */2 Mon')
>>> start = DateTime(2000, 1, 1)
>>> end = start.AddYears(1)
>>> occurrences = s.GetNextOccurrences(start, end)
>>> print '\n'.join([t.ToString('ddd, dd MMM yyyy HH:mm') for t in occurrences])
Mon, 03 Jan 2000 12:00
Mon, 10 Jan 2000 12:00
Mon, 17 Jan 2000 12:00
Mon, 24 Jan 2000 12:00
Mon, 31 Jan 2000 12:00
Mon, 06 Mar 2000 12:00
Mon, 13 Mar 2000 12:00
Mon, 20 Mar 2000 12:00
Mon, 27 Mar 2000 12:00
Mon, 01 May 2000 12:00
Mon, 08 May 2000 12:00
Mon, 15 May 2000 12:00
Mon, 22 May 2000 12:00
Mon, 29 May 2000 12:00
Mon, 03 Jul 2000 12:00
Mon, 10 Jul 2000 12:00
Mon, 17 Jul 2000 12:00
Mon, 24 Jul 2000 12:00
Mon, 31 Jul 2000 12:00
Mon, 04 Sep 2000 12:00
Mon, 11 Sep 2000 12:00
Mon, 18 Sep 2000 12:00
Mon, 25 Sep 2000 12:00
Mon, 06 Nov 2000 12:00
Mon, 13 Nov 2000 12:00
Mon, 20 Nov 2000 12:00
Mon, 27 Nov 2000 12:00

Below is the same example in F# Interactive (fsi.exe):

Microsoft (R) F# 2.0 Interactive build 4.0.40219.1
Copyright (c) Microsoft Corporation. All Rights Reserved.

For help type #help;;

> #r "NCrontab.dll"
-
- open NCrontab
- open System
-
- let schedule = CrontabSchedule.Parse("0 12 * */2 Mon")
- let startDate = DateTime(2000, 1, 1)
- let endDate = startDate.AddYears(1)
-
- let occurrences = schedule.GetNextOccurrences(startDate, endDate)
- occurrences |> Seq.map (fun t -> t.ToString("ddd, dd MMM yyy HH:mm"))
-             |> String.concat "\n"
-             |> printfn "%s";;

--> Referenced 'C:\NCrontab\bin\Release\NCrontab.dll'

Mon, 03 Jan 2000 12:00
Mon, 10 Jan 2000 12:00
Mon, 17 Jan 2000 12:00
Mon, 24 Jan 2000 12:00
Mon, 31 Jan 2000 12:00
Mon, 06 Mar 2000 12:00
Mon, 13 Mar 2000 12:00
Mon, 20 Mar 2000 12:00
Mon, 27 Mar 2000 12:00
Mon, 01 May 2000 12:00
Mon, 08 May 2000 12:00
Mon, 15 May 2000 12:00
Mon, 22 May 2000 12:00
Mon, 29 May 2000 12:00
Mon, 03 Jul 2000 12:00
Mon, 10 Jul 2000 12:00
Mon, 17 Jul 2000 12:00
Mon, 24 Jul 2000 12:00
Mon, 31 Jul 2000 12:00
Mon, 04 Sep 2000 12:00
Mon, 11 Sep 2000 12:00
Mon, 18 Sep 2000 12:00
Mon, 25 Sep 2000 12:00
Mon, 06 Nov 2000 12:00
Mon, 13 Nov 2000 12:00
Mon, 20 Nov 2000 12:00
Mon, 27 Nov 2000 12:00

Below is the same example in C# Interactive (csi.exe):

Microsoft (R) Visual C# Interactive Compiler version 1.2.0.60317
Copyright (C) Microsoft Corporation. All rights reserved.

Type "#help" for more information.
> #r "NCrontab.dll"
> using NCrontab;
> var s = CrontabSchedule.Parse("0 12 * */2 Mon");
> var start = new DateTime(2000, 1, 1);
> var end = start.AddYears(1);
> var occurrences = s.GetNextOccurrences(start, end);
> Console.WriteLine(string.Join(Environment.NewLine,
.     from t in occurrences
.     select $"{t:ddd, dd MMM yyyy HH:mm}"));
Mon, 03 Jan 2000 12:00
Mon, 10 Jan 2000 12:00
Mon, 17 Jan 2000 12:00
Mon, 24 Jan 2000 12:00
Mon, 31 Jan 2000 12:00
Mon, 06 Mar 2000 12:00
Mon, 13 Mar 2000 12:00
Mon, 20 Mar 2000 12:00
Mon, 27 Mar 2000 12:00
Mon, 01 May 2000 12:00
Mon, 08 May 2000 12:00
Mon, 15 May 2000 12:00
Mon, 22 May 2000 12:00
Mon, 29 May 2000 12:00
Mon, 03 Jul 2000 12:00
Mon, 10 Jul 2000 12:00
Mon, 17 Jul 2000 12:00
Mon, 24 Jul 2000 12:00
Mon, 31 Jul 2000 12:00
Mon, 04 Sep 2000 12:00
Mon, 11 Sep 2000 12:00
Mon, 18 Sep 2000 12:00
Mon, 25 Sep 2000 12:00
Mon, 06 Nov 2000 12:00
Mon, 13 Nov 2000 12:00
Mon, 20 Nov 2000 12:00
Mon, 27 Nov 2000 12:00

Below is the same example in C# using dotnet-script:

> #r "nuget:NCrontab"
> using NCrontab;
> var s = CrontabSchedule.Parse("0 12 * */2 Mon");
> var start = new DateTime(2000, 1, 1);
> var end = start.AddYears(1);
> var occurrences = s.GetNextOccurrences(start, end);
> Console.WriteLine(string.Join(Environment.NewLine,
*     from t in occurrences
*     select $"{t:ddd, dd MMM yyyy HH:mm}"));
Mon, 03 Jan 2000 12:00
Mon, 10 Jan 2000 12:00
Mon, 17 Jan 2000 12:00
Mon, 24 Jan 2000 12:00
Mon, 31 Jan 2000 12:00
Mon, 06 Mar 2000 12:00
Mon, 13 Mar 2000 12:00
Mon, 20 Mar 2000 12:00
Mon, 27 Mar 2000 12:00
Mon, 01 May 2000 12:00
Mon, 08 May 2000 12:00
Mon, 15 May 2000 12:00
Mon, 22 May 2000 12:00
Mon, 29 May 2000 12:00
Mon, 03 Jul 2000 12:00
Mon, 10 Jul 2000 12:00
Mon, 17 Jul 2000 12:00
Mon, 24 Jul 2000 12:00
Mon, 31 Jul 2000 12:00
Mon, 04 Sept 2000 12:00
Mon, 11 Sept 2000 12:00
Mon, 18 Sept 2000 12:00
Mon, 25 Sept 2000 12:00
Mon, 06 Nov 2000 12:00
Mon, 13 Nov 2000 12:00
Mon, 20 Nov 2000 12:00
Mon, 27 Nov 2000 12:00

This product includes software developed by the OpenSymphony Group.

More Repositories

1

LinqPadless

LINQPad Queries without LINQPad
C#
268
star
2

Fizzler

.NET CSS Selector Engine
C#
120
star
3

High5

HTML parsing & serialization toolset for .NET Standard
HTML
100
star
4

t5

T5 is T4 (Text Template Transformation Toolkit) for .NET Core
C#
75
star
5

JSONPath

JSONPath (XPath-like syntax for JSON) C# implementation
C#
71
star
6

Hazz

CSS Selectors (via Fizzler) for HtmlAgilityPack (HAP)
C#
57
star
7

StackTraceParser

C# parser for .NET & Mono stack traces
C#
54
star
8

CSharpMinifier

.NET Standard Library & Tool for C# source code minification
C#
33
star
9

Transplator

Simple C# source generator for text templates
C#
26
star
10

WebLinq

LINQ to Web or teaching LINQ to do Web so the Web appears like simple LINQ queries
C#
24
star
11

Optuple

.NET Standard Library for giving (bool, T) Option-like semantics
C#
24
star
12

StackTraceFormatter

C# formatter for .NET & Mono stack traces
C#
23
star
13

Jayrock

JSON & JSON-RPC for .NET Framework & Mono
C#
22
star
14

FakeLinqPad

Fake replacement for LINQPad API
C#
16
star
15

Dsv

.NET Standard Library for Parsing DSV (Delimiter-Separated Values) data like CSV
C#
14
star
16

LINQBridge

Re-implementation of LINQ to Objects for .NET Framework 2.0
C#
13
star
17

Escape

JavaScript parser for .NET Standard based on the Esprima code base
JavaScript
12
star
18

TryParsers

TryParse methods done right for .NET Standard
C#
10
star
19

Jacob

A succinct and compositional .NET API for reading JSON
C#
8
star
20

Gini

INI File Format Parser
C#
7
star
21

CSharpMinifierDemo

Single-Page Application based on Blazor (WebAssembly) demonstrating CSharpMinifier in action
CSS
6
star
22

CSharpSyntaxValidator

.NET Core tool to validate C# source syntax
C#
6
star
23

AngryArrays

Extension methods for transforming arrays
C#
6
star
24

Nunycode

Punycode for .NET derived from https://mths.be/punycode
C#
6
star
25

SplitCsvApp

CSV Splitter Utility
C#
5
star
26

NDate

Date (without Time) for .NET
C#
4
star
27

A1

Column-Row with A1-style parsing & formatting
C#
4
star
28

Spawnr

System.Diagnostics.Process.Start Made Simple
C#
3
star
29

Boxing

.NET Standard library for boxing any value
C#
3
star
30

windu

Disk usage database utility written in C#; that is โš  not actively maintained!
C#
3
star
31

LinqPadCsvFix

Fix CSV Output of LINQPad Reactive Queries
C#
3
star
32

Crockbase32

C# implementation of Douglas Crockford's Base 32
C#
3
star
33

Rejex

Regex ร  la LINQ ๐Ÿšง
C#
3
star
34

XlTableFormat

XlTable format reader
C#
3
star
35

KeyValuePairs

.NET Standard library with helper and extension methods that exclusively deal with KeyValuePair<,>
C#
3
star
36

Gratt

A Generic Vaughn Pratt's top-down operator precedence parser for .NET Standard
C#
3
star
37

dyndlg

Dynamic Dialog Boxes for Windows
C
2
star
38

Interlocker

Interlocked.CompareExchange boilerplate
C#
2
star
39

TextDataReader

An IDataReader implementation for text sources
C#
2
star
40

findpath

Console tool to find a file on the standard Windows search path
C++
2
star
41

Worms

Awaitable Synchronization Primitives Library for .NET
C#
2
star
42

BasicTextFieldParser

Visual Basic's TextFieldParser for .NET Standard
C#
1
star
43

wshgrep

Grep-like using Windows Script Host
JavaScript
1
star
44

VisualFizzler

WinForms Application for visualising CSS Selectors
C#
1
star
45

elvee

Small cross-platform shim in C to run the latest version of an executable
C
1
star
46

cmdqp.cmd

Windows Command Queue Processor Scripts
Batchfile
1
star
47

Delegating.AspNet

.NET Library providing delegated implementations of common ASP.NET interfaces
C#
1
star
48

Builders

This project is work in progress ๐Ÿšง
C#
1
star
49

Gist

My Gists
JavaScript
1
star
50

Kons

Simple Cons List for .NET
C#
1
star
51

Jayrock.Json

.NET Standard Library for reading and writing JSON
C#
1
star
52

secrets.ps

PowerShell scripts to protect secrets in files via Windows DPAPI (Data Protection API)
PowerShell
1
star
53

recolor

.NET Core Tool that colors regex matches on STDIN lines
C#
1
star
54

JsonChecker

http://www.raboof.com/projects/jsonchecker/
C#
1
star
55

OpenWebClient

An โ€œopenโ€ subclass of System.Net.WebClient
C#
1
star
56

pie.ps

Pie = Python installer extraordinaire! A PowerShell script for isolated installation of a project's required versions of Python, pip & packages
PowerShell
1
star
57

WebLinqExamples

Examples of scrapes using WebLINQ
1
star
58

sstart.vbs

WSH script to launch a program without any visible user interface
Visual Basic
1
star
59

Jazmin

.NET Global Tool to filter comments & unnecessary whitespace from JavaScript
C#
1
star
60

NotWebMatrix.Data

Open source clone of mostly WebMatrix.Data and then some more
C#
1
star
61

Choices

Choice types (general discriminated unions) for .NET Standard 1.0+
C#
1
star
62

JmesPath

1
star
63

xls2csv

Utility to format an Excel (BIFF5/BIFF8) worksheet as CSV
JavaScript
1
star
64

Rdatasets.cs

Collection of over a thousand R datasets packaged as a .NET Standard library
C#
1
star
65

Eggado

ADO.NET modernizer
C#
1
star