Scripts


NCrontab Schedule Test

Returns a sampling of the next several date & times scheduled by an NCrontab string.

Usage

Interactive

dotnet fsi .\Test-NCrontab.fsx

Single test, with optional example count

dotnet fsi .\Test-NCrontab.fsx "0 20 29 2 Mon" 42
#r "nuget: NCrontab"
open System
let testNCrontab n s =
    let cron = NCrontab.CrontabSchedule.Parse(s)
    let times = Seq.unfold (fun d -> match cron.GetNextOccurrence(d) with | x -> Some(x,x)) DateTime.Now
    Seq.take n times |> Seq.iter (printfn "%O")
let readNCrontab () =
    printf "ncrontab> "
    match Console.ReadLine () with
    | "quit" | "q" -> false
    | s ->
        testNCrontab 20 s
        true
if fsi.CommandLineArgs.Length < 2 then
    while readNCrontab () do ()
else
    let n = match Int32.TryParse(Array.tryItem 2 fsi.CommandLineArgs |> Option.defaultValue "") with | false,_ -> 20 | true,n -> n
    Array.get fsi.CommandLineArgs 1 |> testNCrontab n
namespace System
val testNCrontab : n:int -> s:string -> unit
val n : int
val s : string
val cron : NCrontab.CrontabSchedule
namespace NCrontab
type CrontabSchedule = new : seconds: CrontabField * minutes: CrontabField * hours: CrontabField * days: CrontabField * months: CrontabField * daysOfWeek: CrontabField -> unit member GetNextOccurrence : baseTime: DateTime -> DateTime + 1 overload member GetNextOccurrences : baseTime: DateTime * endTime: DateTime -> IEnumerable<DateTime> member ToString : unit -> string member TryGetNextOccurrence : baseTime: DateTime * endTime: DateTime -> Nullable<DateTime> static member Parse : expression: string -> CrontabSchedule + 1 overload static member TryParse : expression: string -> CrontabSchedule + 3 overloads static val SecondZero : CrontabField static member Calendar : Calendar
NCrontab.CrontabSchedule.Parse(expression: string) : NCrontab.CrontabSchedule
NCrontab.CrontabSchedule.Parse(expression: string, options: NCrontab.CrontabSchedule.ParseOptions) : NCrontab.CrontabSchedule
val times : seq<DateTime>
module Seq from Microsoft.FSharp.Collections
<summary>Contains operations for working with values of type <see cref="T:Microsoft.FSharp.Collections.seq`1" />.</summary>
val unfold : generator:('State -> ('T * 'State) option) -> state:'State -> seq<'T>
<summary>Returns a sequence that contains the elements generated by the given computation. The given initial <c>state</c> argument is passed to the element generator. For each IEnumerator elements in the stream are generated on-demand by applying the element generator, until a None value is returned by the element generator. Each call to the element generator returns a new residual <c>state</c>.</summary>
<remarks>The stream will be recomputed each time an IEnumerator is requested and iterated for the Seq.</remarks>
<param name="generator">A function that takes in the current state and returns an option tuple of the next element of the sequence and the next state value.</param>
<param name="state">The initial state value.</param>
<returns>The result sequence.</returns>
val d : DateTime
NCrontab.CrontabSchedule.GetNextOccurrence(baseTime: DateTime) : DateTime
NCrontab.CrontabSchedule.GetNextOccurrence(baseTime: DateTime, endTime: DateTime) : DateTime
val x : DateTime
union case Option.Some: Value: 'T -> Option<'T>
<summary>The representation of "Value of type 'T"</summary>
<param name="Value">The input value.</param>
<returns>An option representing the value.</returns>
Multiple items
[<Struct>] type DateTime = new : year: int * month: int * day: int -> unit + 10 overloads member Add : value: TimeSpan -> DateTime member AddDays : value: float -> DateTime member AddHours : value: float -> DateTime member AddMilliseconds : value: float -> DateTime member AddMinutes : value: float -> DateTime member AddMonths : months: int -> DateTime member AddSeconds : value: float -> DateTime member AddTicks : value: int64 -> DateTime member AddYears : value: int -> DateTime ...
<summary>Represents an instant in time, typically expressed as a date and time of day.</summary>

--------------------
DateTime ()
   (+0 other overloads)
DateTime(ticks: int64) : DateTime
   (+0 other overloads)
DateTime(ticks: int64, kind: DateTimeKind) : DateTime
   (+0 other overloads)
DateTime(year: int, month: int, day: int) : DateTime
   (+0 other overloads)
DateTime(year: int, month: int, day: int, calendar: Globalization.Calendar) : DateTime
   (+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int) : DateTime
   (+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, kind: DateTimeKind) : DateTime
   (+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, calendar: Globalization.Calendar) : DateTime
   (+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, millisecond: int) : DateTime
   (+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, millisecond: int, kind: DateTimeKind) : DateTime
   (+0 other overloads)
property DateTime.Now: DateTime with get
<summary>Gets a <see cref="T:System.DateTime" /> object that is set to the current date and time on this computer, expressed as the local time.</summary>
<returns>An object whose value is the current local date and time.</returns>
val take : count:int -> source:seq<'T> -> seq<'T>
<summary>Returns the first N elements of the sequence.</summary>
<remarks>Throws <c>InvalidOperationException</c> if the count exceeds the number of elements in the sequence. <c>Seq.truncate</c> returns as many items as the sequence contains instead of throwing an exception.</remarks>
<param name="count">The number of items to take.</param>
<param name="source">The input sequence.</param>
<returns>The result sequence.</returns>
<exception cref="T:System.ArgumentNullException">Thrown when the input sequence is null.</exception>
<exception cref="T:System.ArgumentException">Thrown when the input sequence is empty.</exception>
<exception cref="T:System.InvalidOperationException">Thrown when count exceeds the number of elements in the sequence.</exception>
val iter : action:('T -> unit) -> source:seq<'T> -> unit
<summary>Applies the given function to each element of the collection.</summary>
<param name="action">A function to apply to each element of the sequence.</param>
<param name="source">The input sequence.</param>
<exception cref="T:System.ArgumentNullException">Thrown when the input sequence is null.</exception>
val printfn : format:Printf.TextWriterFormat<'T> -> 'T
<summary>Print to <c>stdout</c> using the given format, and add a newline.</summary>
<param name="format">The formatter.</param>
<returns>The formatted result.</returns>
val readNCrontab : unit -> bool
val printf : format:Printf.TextWriterFormat<'T> -> 'T
<summary>Print to <c>stdout</c> using the given format.</summary>
<param name="format">The formatter.</param>
<returns>The formatted result.</returns>
type Console = static member Beep : unit -> unit + 1 overload static member Clear : unit -> unit static member GetCursorPosition : unit -> struct (int * int) static member MoveBufferArea : sourceLeft: int * sourceTop: int * sourceWidth: int * sourceHeight: int * targetLeft: int * targetTop: int -> unit + 1 overload static member OpenStandardError : unit -> Stream + 1 overload static member OpenStandardInput : unit -> Stream + 1 overload static member OpenStandardOutput : unit -> Stream + 1 overload static member Read : unit -> int static member ReadKey : unit -> ConsoleKeyInfo + 1 overload static member ReadLine : unit -> string ...
<summary>Represents the standard input, output, and error streams for console applications. This class cannot be inherited.</summary>
Console.ReadLine() : string
[<Struct>] type Int32 = member CompareTo : value: int -> int + 1 overload member Equals : obj: int -> bool + 1 overload member GetHashCode : unit -> int member GetTypeCode : unit -> TypeCode member System.IConvertible.ToBoolean : provider: IFormatProvider -> bool member System.IConvertible.ToByte : provider: IFormatProvider -> byte member System.IConvertible.ToChar : provider: IFormatProvider -> char member System.IConvertible.ToDateTime : provider: IFormatProvider -> DateTime member System.IConvertible.ToDecimal : provider: IFormatProvider -> decimal member System.IConvertible.ToDouble : provider: IFormatProvider -> float ...
<summary>Represents a 32-bit signed integer.</summary>
Int32.TryParse(s: string, result: byref<int>) : bool
Int32.TryParse(s: ReadOnlySpan<char>, result: byref<int>) : bool
Int32.TryParse(s: string, style: Globalization.NumberStyles, provider: IFormatProvider, result: byref<int>) : bool
Int32.TryParse(s: ReadOnlySpan<char>, style: Globalization.NumberStyles, provider: IFormatProvider, result: byref<int>) : bool
type Array = interface ICollection interface IEnumerable interface IList interface IStructuralComparable interface IStructuralEquatable interface ICloneable new : unit -> unit member Clone : unit -> obj member CopyTo : array: Array * index: int -> unit + 1 overload member GetEnumerator : unit -> IEnumerator ...
<summary>Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the base class for all arrays in the common language runtime.</summary>
val tryItem : index:int -> array:'T [] -> 'T option
<summary>Tries to find the nth element in the array. Returns <c>None</c> if index is negative or the input array does not contain enough elements.</summary>
<param name="index">The index of element to retrieve.</param>
<param name="array">The input array.</param>
<returns>The nth element of the array or <c>None</c>.</returns>
<exception cref="T:System.ArgumentNullException">Thrown when the input array is null.</exception>
module Option from Microsoft.FSharp.Core
<summary>Contains operations for working with options.</summary>
<category>Options</category>
val defaultValue : value:'T -> option:'T option -> 'T
<summary>Gets the value of the option if the option is <c>Some</c>, otherwise returns the specified default value.</summary>
<param name="value">The specified default value.</param>
<param name="option">The input option.</param>
<returns>The option if the option is Some, else the default value.</returns>
<remarks>Identical to the built-in <see cref="defaultArg" /> operator, except with the arguments swapped.</remarks>
<example><code> (99, None) ||&gt; Option.defaultValue // evaluates to 99 (99, Some 42) ||&gt; Option.defaultValue // evaluates to 42 </code></example>
val get : array:'T [] -> index:int -> 'T
<summary>Gets an element from an array.</summary>
<param name="array">The input array.</param>
<param name="index">The input index.</param>
<returns>The value of the array at the given index.</returns>
<exception cref="T:System.NullReferenceException">Thrown when the input array is null.</exception>
<exception cref="T:System.IndexOutOfRangeException">Thrown when the index is negative or the input array does not contain enough elements.</exception>