Movatterモバイル変換


[0]ホーム

URL:


cron

package
v2.24.2Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2025 License:AGPL-3.0Imports:5Imported by:0

Details

Repository

github.com/coder/coder

Links

Documentation

Overview

package schedule provides utilities for managing template and workspaceautostart and autostop schedules. This includes utilities for parsing anddeserializing cron-style expressions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

typeSchedule

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

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

funcDaily

func Daily(rawstring) (*Schedule,error)

Daily parses a Schedule from spec scoped to a recurring daily 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 (must be *)

Example Usage:

local_sched, _ := cron.Weekly("59 23 * * *")fmt.Println(sched.Next(time.Now().Format(time.RFC3339)))// Output: 2022-04-04T23:59:00Zus_sched, _ := cron.Weekly("CRON_TZ=US/Central 30 9 * * *")fmt.Println(sched.Next(time.Now()).Format(time.RFC3339))// Output: 2022-04-04T14:30:00Z

funcTimeRangeadded inv2.24.0

func TimeRange(rawstring) (*Schedule,error)

TimeRange parses a Schedule from a cron specification interpreted as a continuous time range.

For example, the expression "* 9-18 * * 1-5" represents a continuous time spanfrom 09:00:00 to 18:59:59, Monday through Friday.

The specification consists of space-delimited fields in the following order:- (Optional) Timezone, e.g., CRON_TZ=US/Central- Minutes: must be "*" to represent the full range within each hour- Hour of day: e.g., 9-18 (required)- Day of month: e.g., * or 1-15 (required)- Month: e.g., * or 1-6 (required)- Day of week: e.g., * or 1-5 (required)

Unlike standard cron, this function interprets the input as a continuous active periodrather than discrete scheduled times.

funcWeekly

func Weekly(rawstring) (*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, _ := cron.Weekly("59 23 *")fmt.Println(sched.Next(time.Now().Format(time.RFC3339)))// Output: 2022-04-04T23:59:00Zus_sched, _ := cron.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

func (sSchedule) Cron()string

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

func (Schedule)DaysOfWeek

func (sSchedule) DaysOfWeek()string

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

func (Schedule)Humanizeadded inv2.4.0

func (sSchedule) Humanize()string

Humanize returns a slightly more human-friendly representation of theschedule.

func (Schedule)IsWithinRangeadded inv2.24.0

func (sSchedule) IsWithinRange(ttime.Time)bool

IsWithinRange interprets a cron spec as a continuous time range,and returns whether the provided time value falls within that range.

For example, the expression "* 9-18 * * 1-5" represents a continuous time rangefrom 09:00:00 to 18:59:59, Monday through Friday.

func (Schedule)Location

func (sSchedule) Location() *time.Location

Location returns the IANA location for the schedule.

func (Schedule)Min

func (sSchedule) 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 (sSchedule) Next(ttime.Time)time.Time

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

func (Schedule)String

func (sSchedule) String()string

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

func (Schedule)Time

func (sSchedule) Time()string

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

func (Schedule)TimeParsedadded inv2.2.0

func (sSchedule) TimeParsed()time.Time

TimeParsed returns the parsed time.Time of the minute and hour fields. If thetime cannot be represented in a valid time.Time, a zero time is returned.

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp