awscron

package
v1.3.5 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package awscron implements the field-matching primitives shared by AWS's cron(...) schedule expression dialects: numeric values, three-letter names, *, ?, ranges, steps, and comma lists for a single field, plus AWS's day-of-month/day-of-week OR semantics.

AWS does not use one dialect. EventBridge Rules and Redshift ScheduledAction both require six fields ending in Year (aws-sdk-go-v2 eventbridge@v1.48.4 api_op_PutRule.go:118, example "cron(0 20 * * ? *)"; redshift@v1.65.4 api_op_CreateScheduledAction.go:104-105, example "cron(0 10 ? * MON *)"), while CloudWatch alarm mute schedules use five fields with no Year (cloudwatch@v1.66.3 types/types.go:3441-3442, example "cron(0 2 * * *)"). Redshift's at() form carries seconds (api_op_CreateScheduledAction.go:101-102, "at(2016-03-04T17:27:00)"); CloudWatch's does not (types/types.go:3459, "at(2024-05-10T14:00)"); EventBridge Rules has no at() form at all.

Because the field count and the at() layout both vary by caller, this package does not assemble a cron expression type of its own -- doing so would force every caller onto one dialect and silently accept expressions the real service rejects. Instead each caller defines its own expression struct with its own field count and at() parsing, and calls MatchField per field and MatchDayFields for the day-of-month/day-of-week rule.

Index

Constants

View Source
const (
	MinuteMin = 0
	MinuteMax = 59

	HourMin = 0
	HourMax = 23

	MonthMin = 1
	MonthMax = 12

	DayOfMonthMin = 1
	DayOfMonthMax = 31

	DayOfWeekMin = 0
	DayOfWeekMax = 6

	YearMin = 1970
	YearMax = 2199
)

Variables

This section is empty.

Functions

func MatchDayFields

func MatchDayFields(dayOfMonth, dayOfWeek string, t time.Time) bool

MatchDayFields evaluates the AWS day-of-month/day-of-week rule: a wildcard ("*" or "?") field defers entirely to the other; when both are concrete, AWS matches if either is satisfied.

func MatchField

func MatchField(kind FieldKind, field string, val, fieldMin, fieldMax int) bool

MatchField reports whether val matches a cron field: *, ?, or a comma-separated list of tokens (numeric, name, range, or step).

func TokenValue

func TokenValue(kind FieldKind, token string) (int, bool)

TokenValue resolves a single cron token to its comparable integer value for the given field kind: three-letter names for month/day-of-week, otherwise a plain number. Numeric day-of-week tokens are converted from AWS's 1-7 (Sunday = 1) convention to Go's time.Weekday 0-6 (Sunday = 0) so callers can compare directly against int(t.Weekday()).

Types

type FieldKind

type FieldKind int

FieldKind identifies which cron field a token belongs to, so numeric/name resolution can apply AWS's field-specific conventions: month and day-of-week accept three-letter names, and AWS's day-of-week numbering (1-7, where 1 = Sunday) differs from Go's time.Weekday (0-6, where 0 = Sunday).

const (
	FieldMinute FieldKind = iota
	FieldHour
	FieldDayOfMonth
	FieldMonth
	FieldDayOfWeek
	FieldYear
)

Jump to

Keyboard shortcuts

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