schedule

package
v0.0.0-...-052fa94 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2026 License: Apache-2.0 Imports: 7 Imported by: 1

README

Package cloudeng.io/datetime/schedule

import cloudeng.io/datetime/schedule

Package schedule provides support for scheduling events based on dates and times.

Types

Type ActionSpec
type ActionSpec[T any] struct {
	Name    string
	Due     datetime.TimeOfDay
	Dynamic DynamicTimeOfDaySpec
	Repeat  RepeatSpec
	T       T
}

ActionSpec represents a specification of an action to be taken at specific times of that day. The specification may refer to a dynamically evaluated time of day (eg. sunrise/sunset) with an offset. In addition it may specify a repeat interval and an optional number of times for the action to be repeated.

Methods
func (a ActionSpec[T]) Evaluate(cd datetime.CalendarDate, place datetime.Place) ActionSpec[T]

Evaluate returns a new ActionSpec with the Due field set to the result of evaluating the DynamicDue field if it is non-nil (with the DynamicOffset applied).

Type ActionSpecs
type ActionSpecs[T any] []ActionSpec[T]
Methods
func (a ActionSpecs[T]) Evaluate(cd datetime.CalendarDate, place datetime.Place) ActionSpecs[T]

Evaluate returns a new ActionSpecs with each of the ActionSpecs evaluated, that is, with any Dynamic functions evaluated and the results stored in the Due field. The returned ActionSpecs have their Dynamic fields zeroed out.

func (a ActionSpecs[T]) Sort()

Sort by due time and then by name.

func (a ActionSpecs[T]) SortStable()

Sort by due time, but preserve the order of actions with the same due time.

Type Active
type Active[T any] struct {
	Name string
	When time.Time
	T    T
}

Active represents the next scheduled action, ie. the one to be 'active' at time 'When'.

Type AnnualScheduler
type AnnualScheduler[T any] struct {
	// contains filtered or unexported fields
}

AnnualScheduler provides a way to iterate over the specified actions for a single year.

Functions
func NewAnnualScheduler[T any](actions ActionSpecs[T]) *AnnualScheduler[T]

NewAnnualScheduler returns a new annual scheduler with the supplied schedule.

Methods
func (s *AnnualScheduler[T]) Scheduled(yp datetime.YearPlace, dates Dates, bounds datetime.DateRange) iter.Seq[Scheduled[T]]

Scheduled returns an iterator over the scheduled actions for the given year and place that returns all of the scheduled actions for each day that has scheduled Actions. It will evaluate any dynamic due times and sort the actions by their evaluated due time.

Type Dates
type Dates struct {
	Months       datetime.MonthList            // Whole months to include.
	MirrorMonths bool                          // Include the 'mirror' months of those in For.
	Ranges       datetime.DateRangeList        // Include specific date ranges.
	Dynamic      datetime.DynamicDateRangeList // Functions to generate dates that vary by year, such as solstices, seasons or holidays.
	Constraints  datetime.Constraints          // Constraints to be applied, such as weekdays/weekends etc.
}

Dates represents a set of dates expressed as a combination of months, date ranges and constraints on those dates (eg. weekdays in March).

Methods
func (d Dates) EvaluateDateRanges(year int, bounds datetime.DateRange) datetime.DateRangeList

EvaluateDateRanges returns the list of date ranges that are represented by the totality of the information represented by Dates instance, including the evaluation of dynamic date ranges. The result is bounded by supplied bounds date range.

func (d Dates) String() string
Type DynamicTimeOfDaySpec
type DynamicTimeOfDaySpec struct {
	Due    datetime.DynamicTimeOfDay
	Offset time.Duration
}

DynamicTimeOfDaySpec represents a time of day that is dynamically evaluated and offset with a fixed duration.

Type RepeatSpec
type RepeatSpec struct {
	Interval time.Duration
	Repeats  int
}

RepeatSpec represents a repeat interval and an optional number of times for an action to be repeated.

Type Scheduled
type Scheduled[T any] struct {
	Date  datetime.CalendarDate
	Specs ActionSpecs[T]
}

Scheduled specifies the set of actions scheduled for a given date.

Methods
func (s Scheduled[T]) Active(place datetime.Place) iter.Seq[Active[T]]

Active is an iterator that returns the next scheduled action for the given year and place.

Documentation

Overview

Package schedule provides support for scheduling events based on dates and times.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActionSpec

type ActionSpec[T any] struct {
	Name    string
	Due     datetime.TimeOfDay
	Dynamic DynamicTimeOfDaySpec
	Repeat  RepeatSpec
	T       T
}

ActionSpec represents a specification of an action to be taken at specific times of that day. The specification may refer to a dynamically evaluated time of day (eg. sunrise/sunset) with an offset. In addition it may specify a repeat interval and an optional number of times for the action to be repeated.

func (ActionSpec[T]) Evaluate

func (a ActionSpec[T]) Evaluate(cd datetime.CalendarDate, place datetime.Place) ActionSpec[T]

Evaluate returns a new ActionSpec with the Due field set to the result of evaluating the DynamicDue field if it is non-nil (with the DynamicOffset applied).

type ActionSpecs

type ActionSpecs[T any] []ActionSpec[T]

func (ActionSpecs[T]) Evaluate

func (a ActionSpecs[T]) Evaluate(cd datetime.CalendarDate, place datetime.Place) ActionSpecs[T]

Evaluate returns a new ActionSpecs with each of the ActionSpecs evaluated, that is, with any Dynamic functions evaluated and the results stored in the Due field. The returned ActionSpecs have their Dynamic fields zeroed out.

func (ActionSpecs[T]) Sort

func (a ActionSpecs[T]) Sort()

Sort by due time and then by name.

func (ActionSpecs[T]) SortStable

func (a ActionSpecs[T]) SortStable()

Sort by due time, but preserve the order of actions with the same due time.

type Active

type Active[T any] struct {
	Name string
	When time.Time
	T    T
}

Active represents the next scheduled action, ie. the one to be 'active' at time 'When'.

type AnnualScheduler

type AnnualScheduler[T any] struct {
	// contains filtered or unexported fields
}

AnnualScheduler provides a way to iterate over the specified actions for a single year.

func NewAnnualScheduler

func NewAnnualScheduler[T any](actions ActionSpecs[T]) *AnnualScheduler[T]

NewAnnualScheduler returns a new annual scheduler with the supplied schedule.

func (*AnnualScheduler[T]) Scheduled

func (s *AnnualScheduler[T]) Scheduled(yp datetime.YearPlace, dates Dates, bounds datetime.DateRange) iter.Seq[Scheduled[T]]

Scheduled returns an iterator over the scheduled actions for the given year and place that returns all of the scheduled actions for each day that has scheduled Actions. It will evaluate any dynamic due times and sort the actions by their evaluated due time.

type Dates

type Dates struct {
	Months       datetime.MonthList            // Whole months to include.
	MirrorMonths bool                          // Include the 'mirror' months of those in For.
	Ranges       datetime.DateRangeList        // Include specific date ranges.
	Dynamic      datetime.DynamicDateRangeList // Functions to generate dates that vary by year, such as solstices, seasons or holidays.
	Constraints  datetime.Constraints          // Constraints to be applied, such as weekdays/weekends etc.
}

Dates represents a set of dates expressed as a combination of months, date ranges and constraints on those dates (eg. weekdays in March).

func (Dates) EvaluateDateRanges

func (d Dates) EvaluateDateRanges(year int, bounds datetime.DateRange) datetime.DateRangeList

EvaluateDateRanges returns the list of date ranges that are represented by the totality of the information represented by Dates instance, including the evaluation of dynamic date ranges. The result is bounded by supplied bounds date range.

func (Dates) String

func (d Dates) String() string

type DynamicTimeOfDaySpec

type DynamicTimeOfDaySpec struct {
	Due    datetime.DynamicTimeOfDay
	Offset time.Duration
}

DynamicTimeOfDaySpec represents a time of day that is dynamically evaluated and offset with a fixed duration.

type RepeatSpec

type RepeatSpec struct {
	Interval time.Duration
	Repeats  int
}

RepeatSpec represents a repeat interval and an optional number of times for an action to be repeated.

type Scheduled

type Scheduled[T any] struct {
	Date  datetime.CalendarDate
	Specs ActionSpecs[T]
}

Scheduled specifies the set of actions scheduled for a given date.

func (Scheduled[T]) Active

func (s Scheduled[T]) Active(place datetime.Place) iter.Seq[Active[T]]

Active is an iterator that returns the next scheduled action for the given year and place.

Jump to

Keyboard shortcuts

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