cronparse

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2020 License: MIT Imports: 4 Imported by: 0

README

cronparse

CircleCI codecov Go Report Card Godoc

cronparse is a tool that can parse and expand cron expressions into the times that said expression will run at.

e.g.

$ cronparse */15 0 1,15 * 1-5 /usr/bin/find
minute         0 15 30 45
hour           0
day of month   1 15
month          1 2 3 4 5 6 7 8 9 10 11 12
day of week    1 2 3 4 5
command        /usr/bin/find

Contents

Building

cronparse is built using Go. To build cronparse you require the Go tool, you can find how to do that for your specific system here.

Once you have installed Go, you can get up and running by cloning this repository to a location of your choice and running:

go run cmd/cronparse/main.go */15 0 1,15 * 1-5 /usr/bin/find

Alternatively if you have your $GOPATH/bin added to your $PATH you can run:

go get -u github.com/alistairjudson/cronparse/cmd/cronparse
Tests

To run the tests you can simply run:

go test ./...
Linting

This project uses golangci-lint in order to lint the project it is configured by the .golangci.yml file.

Architecture

cronparse has a couple of stages when it comes to parsing interpreting the expression, these stages are:

Lexical Analysis

cronparse uses a finite state machine to tokenise the individual components of the input into tokens, the way that this is implemented is heavily inspired by the approach taken by Rob Pike in this talk. If you want to find out more about this, this blog post is pretty cool.

In the tokenisation stage, the values themselves are not validated, only that the syntax of the expression matches that of a component of a cron expression.

Parsing

The parsing of the cron expression is pretty lazy, it just uses some simple pattern matching in order to validate the expressions, and expand the values that they represent.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CronParser = Parser{
	newComponentParser("minute", parse.MinuteParser.Parse),
	newComponentParser("hour", parse.HourParser.Parse),
	newComponentParser("day of month", parse.DayOfMonthParser.Parse),
	newComponentParser("month", parse.MonthParser.Parse),
	newComponentParser("day of week", parse.DayOfWeekParser.Parse),
}

CronParser is a type that can parse the components of a cron expression and expand them into the values that they run on

Functions

This section is empty.

Types

type ComponentParser

type ComponentParser struct {
	Name   string
	Parser PartParser
}

ComponentParser is a parser for a specific portion of a cron expression

type Numberer

type Numberer interface {
	Numbers() []int
}

Numberer is a type that can give you the expanded cron values

type ParsedComponent

type ParsedComponent struct {
	Name    string
	Numbers []int
}

ParsedComponent is the result of parsing a cron component

func (ParsedComponent) String

func (p ParsedComponent) String() string

String implements fmt.Stringer and pretty prints a parsed cron component

type Parser

type Parser []ComponentParser

Parser is a type that can hold multiple ComponentParsers

func (Parser) Parse

func (p Parser) Parse(components []string) ([]ParsedComponent, error)

Parse will parse all of the components with their respective component parser

type PartParser

type PartParser interface {
	Parse(component string) (Numberer, error)
}

PartParser is a type that can parse part of a cron expression

Directories

Path Synopsis
cmd
internal

Jump to

Keyboard shortcuts

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