crondescriptor

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2020 License: MIT Imports: 7 Imported by: 14

Documentation

Overview

Package crondescriptor converts cron expressions into human readable strings. The package includes four options for minor customization of output.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidDescriptionType = fmt.Errorf("invalid description type provided")
	ErrInvalidSegmentCase     = fmt.Errorf("invalid case reached; please investigate")
	ErrBlankExpression        = fmt.Errorf("expression cannot be blank")
	ErrInvalidFieldCount      = fmt.Errorf("at least five fields are required")
	ErrFieldCountExceeded     = fmt.Errorf("expression has too many fields; should not exceed 7 fields")
	ErrWeekStartIsZero        = fmt.Errorf("week start already 0; check DayOfWeekIndexZero option")
	ErrInvalidCharacters      = fmt.Errorf("invalid character(s). allowed value: 0-23. allowed special characters: '*' ',' '-'")
	ErrInvalidMinuteFormat    = fmt.Errorf("invalid minute format")
	ErrInvalidSecondsValue    = fmt.Errorf("invalid seconds value. only 0-59 allowed)")
	ErrInvalidDayOfWeekRange  = fmt.Errorf("day of week range can only be 0-6 or 1-7 depending on DayOfWeekIndexZero option")
)
View Source
var CronDaysLong = []string{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}

CronDaysLong contains the days of the week long form

View Source
var CronDaysShort = []string{"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"}

CronDaysShort contains the days of the week short form

View Source
var CronMonths = []string{"JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"}

CronMonths are zero indexed with Jan

Functions

This section is empty.

Types

type CasingType

type CasingType int

CasingType for the type of casing transformatin

const (
	// CasingTypeSentence style casing
	CasingTypeSentence CasingType = iota
	// CasingTypeTitle style casing
	CasingTypeTitle
	// CasingTypeLower style casing
	CasingTypeLower
)

type CronDescriptor

type CronDescriptor struct {
	Expression string

	Options Options
	Logger  *zap.Logger
	// contains filtered or unexported fields
}

CronDescriptor contains the cron expression, the array equivalent, and other settings

func NewCronDescriptor

func NewCronDescriptor(cronExpr string) (*CronDescriptor, error)

NewCronDescriptor creates a new CronDescriptor object

func NewCronDescriptorWithOptions

func NewCronDescriptorWithOptions(cronExpr string, options Options) (*CronDescriptor, error)

NewCronDescriptorWithOptions creates a new CronDescriptor object

func (*CronDescriptor) GetDescription

func (cd *CronDescriptor) GetDescription(descriptionType DescriptionTypeEnum) (*string, error)

GetDescription returns the description of the expression based on the parameter provided

func (*CronDescriptor) Parse

func (cd *CronDescriptor) Parse(expression string) (err error)

Parse normalizes and breaks a cron expression into an array of length seven

type DescriptionTypeEnum

type DescriptionTypeEnum int

DescriptionTypeEnum for the type of description

const (
	// Full - provide full description
	Full DescriptionTypeEnum = iota
	// TimeOfDay - only the time of the day portion of the expression
	TimeOfDay
	// Seconds - only the seconds portion of the expression
	Seconds
	// Minutes - only the minutes portion of the expression
	Minutes
	// Hours - only the hours portion of the expression
	Hours
	// DayOfWeek - only the day of the week portion of the expression
	DayOfWeek
	// Month - only the month portion of the expression
	Month
	// DayOfMonth - only the day of the month portion of the expression
	DayOfMonth
	// Year - only the Year portion of the expression
	Year
)

type Options

type Options struct {
	CasingType          CasingType
	DayOfWeekIndexZero  bool
	Use24HourTimeFormat bool
	Verbose             bool
}

Options for the CronDescriptor functions

Jump to

Keyboard shortcuts

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