cron

package module
v0.0.0-...-4bb0a20 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 6, 2020 License: MIT Imports: 5 Imported by: 9

README

cron

A fast non-allocating cron parser in ragel and golang.

features

  • standard five-position cron
  • six-position cron with seconds
  • seven-position cron with seconds and years
  • case-insensitive days of the week
  • case-insensitive month names
  • Quartz compatible ranges e.g.: 4/10, SUN-THURS/2
  • timezone handling (other than UTC)
  • Quartz compatible # handling, i.e. 5#3 meaning the third friday of the month
  • Quartz compatible L handling, i.e. 5L in the day of week field meaning the last friday of a month, or 3L in the day of month field meaning third to last day of the month

performance

On a 3.1 Ghz Core i7 MacBook Pro (Retina, 15-inch, Mid 2017):

BenchmarkParse/0_*_*_*_*_*_*-8 20000000 63.5 ns/op 0 B/op
BenchmarkParse/1-6/2_*_*_*_Feb-Oct/3_*_*-8 10000000 118 ns/op 0 B/op
BenchmarkParse/1-6/2_*_*_*_Feb-Oct/3_*_2020/4-8 1000000 146 ns/op 0 B/op

TODO

  • Once we are done adding all of the Quartz cron features, to copy and pass all of Quartz's parsing tests.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Parsed

type Parsed struct {
	// contains filtered or unexported fields
}

Parsed is a parsed cron string. It can be used to find the next instance of a cron task.

func ParseUTC

func ParseUTC(s string) (Parsed, error)

ParseUTC parses a cron string in UTC timezone.

Example
package main

import (
	"fmt"
	"time"

	"github.com/influxdata/cron"
)

func main() {
	p, err := cron.ParseUTC("10 * * * * *")
	if err != nil {
		fmt.Println(err)
	}
	ts, err := p.Next(time.Date(1999, 12, 31, 23, 59, 59, 0, time.UTC))
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(ts)
}
Output:

2000-01-01 00:00:10 +0000 UTC

func (*Parsed) Count

func (nt *Parsed) Count(from, to time.Time) (count int)

Count gives us a count of the number of calls Parsed.Next would take to iterate though the time interval [from, to). We try to be O(1) where possible. However for periods longer than a month that don't use @every, it is worst case O(m) where m is the number of months in the interval.

func (Parsed) Next

func (nt Parsed) Next(from time.Time) (time.Time, error)

Next returns the next time a cron task should run given a Parsed cron string. It will error if the Parsed is not from a zero value.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL