schedule

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: May 16, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package schedule provides types to define time switch schedule intervals for outlets.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DayTime

type DayTime struct {
	Hour   int `json:"hour"`
	Minute int `json:"minute"`
}

DayTime is a time definition that is agnostic of concrete dates and is only concerned about hours and minutes. This can be used to define a point in time that applies to any day of the week.

func NewDayTime

func NewDayTime(hour, minute int) DayTime

NewDayTime create a new DayTime from an hour and minute.

func (DayTime) After

func (t DayTime) After(other DayTime) bool

After returns true if t is after other.

func (DayTime) Before

func (t DayTime) Before(other DayTime) bool

Before returns true if t is before other.

func (DayTime) Between

func (t DayTime) Between(start, end DayTime) bool

Between returns true if t is between start and end or equal to start.

func (DayTime) Equal

func (t DayTime) Equal(other DayTime) bool

Equal returns true if t is equal to other.

type Interval

type Interval struct {
	ID       string         `json:"id"`
	Enabled  bool           `json:"enabled"`
	Weekdays []time.Weekday `json:"weekdays"`
	From     DayTime        `json:"from"`
	To       DayTime        `json:"to"`
}

Interval defines a time frame consisting of a start and end time and a list of weekdays for which the interval is valid.

func (Interval) Contains

func (i Interval) Contains(t time.Time) bool

Contains returns true if interval is enabled and t lies within.

type Schedule

type Schedule struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Schedule is a collection of intervals.

func New

func New() *Schedule

New creates a new empty *Schedule.

func NewWithIntervals

func NewWithIntervals(intervals []Interval) *Schedule

NewWithIntervals create a new *Schedule with intervals.

func (*Schedule) AddInterval

func (s *Schedule) AddInterval(interval Interval) error

AddInterval adds an interval to the schedule of an outlet.

func (*Schedule) Contains

func (s *Schedule) Contains(t time.Time) bool

Contains returns true if any of the intervals contains t.

func (*Schedule) DeleteInterval

func (s *Schedule) DeleteInterval(interval Interval) error

DeleteInterval deletes an interval of the schedule of an outlet. Will return an error if the interval does not exist.

func (*Schedule) Enabled

func (s *Schedule) Enabled() bool

Enabled returns true if any of the intervals is enabled.

func (*Schedule) MarshalJSON

func (s *Schedule) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

This hides that fact that *Schedule wraps a slice of Interval in the marshalled json.

func (*Schedule) UnmarshalJSON

func (s *Schedule) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

This ensures that the json bytes are correctly unmarshalled into the internal slice of Interval values.

func (*Schedule) UpdateInterval

func (s *Schedule) UpdateInterval(interval Interval) error

UpdateInterval updates an interval of the schedule of an outlet. Will return an error if the interval does not exist.

Jump to

Keyboard shortcuts

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