schedule

package
v0.8.7 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2022 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

package schedule provides utilities for parsing and deserializing cron-style expressions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Schedule

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

Schedule represents a cron schedule. It's essentially a wrapper for robfig/cron/v3 that has additional convenience methods.

func Weekly

func Weekly(raw string) (*Schedule, error)

Weekly parses a Schedule from spec scoped to a recurring weekly event. Spec consists of the following space-delimited fields, in the following order: - timezone e.g. CRON_TZ=US/Central (optional) - minutes of hour e.g. 30 (required) - hour of day e.g. 9 (required) - day of month (must be *) - month (must be *) - day of week e.g. 1 (required)

Example Usage:

local_sched, _ := schedule.Weekly("59 23 *")
fmt.Println(sched.Next(time.Now().Format(time.RFC3339)))
// Output: 2022-04-04T23:59:00Z

us_sched, _ := schedule.Weekly("CRON_TZ=US/Central 30 9 1-5")
fmt.Println(sched.Next(time.Now()).Format(time.RFC3339))
// Output: 2022-04-04T14:30:00Z

func (Schedule) Cron added in v0.5.7

func (s Schedule) Cron() string

Cron returns the cron spec for the schedule with the leading CRON_TZ stripped, if present.

func (Schedule) DaysOfWeek added in v0.7.0

func (s Schedule) DaysOfWeek() string

DaysOfWeek returns a humanized form of the day-of-week field.

func (Schedule) Location added in v0.7.0

func (s Schedule) Location() *time.Location

Location returns the IANA location for the schedule.

func (Schedule) Min added in v0.6.3

func (s Schedule) Min() time.Duration

Min returns the minimum duration of the schedule. This is calculated as follows:

  • Let t(0) be a given point in time (1970-01-01T01:01:01Z00:00)
  • Let t(max) be 168 hours after t(0).
  • Let t(1) be the next scheduled time after t(0).
  • Let t(n) be the next scheduled time after t(n-1).
  • Then, the minimum duration of s d(min) = min( t(n) - t(n-1) ∀ n ∈ N, t(n) < t(max) )

func (Schedule) Next

func (s Schedule) Next(t time.Time) time.Time

Next returns the next time in the schedule relative to t.

func (Schedule) String

func (s Schedule) String() string

String serializes the schedule to its original human-friendly format. The leading CRON_TZ is maintained.

func (Schedule) Time added in v0.7.2

func (s Schedule) Time() string

Time returns a humanized form of the minute and hour fields.

Jump to

Keyboard shortcuts

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