rule

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2019 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Clock

type Clock time.Duration

Clock represents wall-clock time. It is a duration since midnight.

func NewClock

func NewClock(hour, minute int) Clock

NewClock returns a Clock value equal to the provided 24-hour value and minute.

func ParseClock

func ParseClock(value string) (Clock, error)

ParseClock will return a new Clock value given a value in the format of '15:04' or '15:04:05'. The resulting value will be truncated to the minute.

func (Clock) Format

func (c Clock) Format(layout string) string

Format will format the clock value using the same format string used by time.Time.

func (Clock) Hour

func (c Clock) Hour() int

Hour returns the hour of the Clock value.

func (Clock) Minute

func (c Clock) Minute() int

Minute returns the minute of the Clock value.

func (*Clock) Scan

func (c *Clock) Scan(value interface{}) error

Scan implements the sql.Scanner interface.

func (Clock) String

func (c Clock) String() string

String returns a string representation of the format '15:04'.

func (Clock) Value

func (c Clock) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

type DB

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

func NewDB

func NewDB(ctx context.Context, db *sql.DB) (*DB, error)

func (*DB) Add

func (db *DB) Add(ctx context.Context, r *Rule) (*Rule, error)

func (*DB) CreateRuleTx

func (db *DB) CreateRuleTx(ctx context.Context, tx *sql.Tx, r *Rule) (*Rule, error)

func (*DB) Delete

func (db *DB) Delete(ctx context.Context, ruleID string) error

func (*DB) DeleteByTarget

func (db *DB) DeleteByTarget(ctx context.Context, scheduleID string, target assignment.Target) error

DeleteByTarget removes all rules for a schedule pointing to the specified target.

func (*DB) DeleteManyTx

func (db *DB) DeleteManyTx(ctx context.Context, tx *sql.Tx, ruleIDs []string) error

func (*DB) DeleteTx

func (db *DB) DeleteTx(ctx context.Context, tx *sql.Tx, ruleID string) error

func (*DB) FindAll

func (db *DB) FindAll(ctx context.Context, scheduleID string) ([]Rule, error)

func (*DB) FindAllTx

func (db *DB) FindAllTx(ctx context.Context, tx *sql.Tx, scheduleID string) ([]Rule, error)

func (*DB) FindAllWithUsers

func (db *DB) FindAllWithUsers(ctx context.Context, scheduleID string) ([]Rule, error)

func (*DB) FindByTargetTx

func (db *DB) FindByTargetTx(ctx context.Context, tx *sql.Tx, scheduleID string, target assignment.Target) ([]Rule, error)

func (*DB) FindOne

func (db *DB) FindOne(ctx context.Context, ruleID string) (*Rule, error)

func (*DB) FindScheduleID

func (db *DB) FindScheduleID(ctx context.Context, ruleID string) (string, error)

func (*DB) Update

func (db *DB) Update(ctx context.Context, r *Rule) error

func (*DB) UpdateTx

func (db *DB) UpdateTx(ctx context.Context, tx *sql.Tx, r *Rule) error

type ReadStore

type ReadStore interface {
	FindScheduleID(context.Context, string) (string, error)
	FindOne(context.Context, string) (*Rule, error)
	FindAll(ctx context.Context, scheduleID string) ([]Rule, error)
	FindAllTx(ctx context.Context, tx *sql.Tx, scheduleID string) ([]Rule, error)

	// FindAllWithUsers works like FindAll but resolves rotations to the active user.
	// This is reflected in the Target attribute.
	// Rules pointing to inactive rotations (no participants) are omitted.
	FindAllWithUsers(ctx context.Context, scheduleID string) ([]Rule, error)
}

type Rule

type Rule struct {
	ID         string `json:"id"`
	ScheduleID string `json:"schedule_id"`
	WeekdayFilter
	Start     Clock     `json:"start"`
	End       Clock     `json:"end"`
	CreatedAt time.Time `json:"created_at"`
	Target    assignment.Target
}

func NewAlwaysActive

func NewAlwaysActive(scheduleID string, tgt assignment.Target) *Rule

func (Rule) AlwaysActive

func (r Rule) AlwaysActive() bool

AlwaysActive will return true if the rule will always be active.

func (Rule) EndTime

func (r Rule) EndTime(t time.Time) time.Time

EndTime will return the next time the rule would be inactive. If the rule is currently inactive, it will return the end of the next shift.

func (Rule) IsActive

func (r Rule) IsActive(t time.Time) bool

IsActive determines if the rule is active in the given moment in time, in the location of t.

func (Rule) NeverActive

func (r Rule) NeverActive() bool

NeverActive returns true if the rule will never be active.

func (Rule) Normalize

func (r Rule) Normalize() (*Rule, error)

func (Rule) StartTime

func (r Rule) StartTime(t time.Time) time.Time

StartTime will return the next time the rule would be active. If the rule is currently active, it will return the time it became active (in the past).

If the rule is NeverActive or AlwaysActive, zero time is returned.

func (Rule) String

func (r Rule) String() string

String returns a human-readable string describing the rule

type ScheduleTriggerFunc

type ScheduleTriggerFunc func(string)

type Store

type Store interface {
	ReadStore
	Add(context.Context, *Rule) (*Rule, error)
	CreateRuleTx(context.Context, *sql.Tx, *Rule) (*Rule, error)
	Update(context.Context, *Rule) error
	UpdateTx(context.Context, *sql.Tx, *Rule) error
	Delete(context.Context, string) error
	DeleteTx(context.Context, *sql.Tx, string) error
	DeleteManyTx(context.Context, *sql.Tx, []string) error
	DeleteByTarget(ctx context.Context, scheduleID string, target assignment.Target) error
	FindByTargetTx(ctx context.Context, tx *sql.Tx, scheduleID string, target assignment.Target) ([]Rule, error)
}

type WeekdayFilter

type WeekdayFilter [7]byte

func (WeekdayFilter) Day

func (f WeekdayFilter) Day(d time.Weekday) bool

Day will return true if the given weekday is enabled.

func (WeekdayFilter) DaysSince

func (f WeekdayFilter) DaysSince(d time.Weekday, enabled bool) int

DaysSince will give the number of days since an enabled day from the given weekday. -1 is returned if all days are disabled.

func (WeekdayFilter) DaysUntil

func (f WeekdayFilter) DaysUntil(d time.Weekday, enabled bool) int

DaysUntil will give the number of days until a matching day from the given weekday. -1 is returned if no days match.

func (*WeekdayFilter) SetDay

func (f *WeekdayFilter) SetDay(d time.Weekday, enabled bool)

SetDay will update the filter for the given weekday.

func (WeekdayFilter) String

func (f WeekdayFilter) String() string

String returns a string representation of the WeekdayFilter.

func (WeekdayFilter) Value

func (f WeekdayFilter) Value() (driver.Value, error)

Value converts the WeekdayFilter to a DB array of bool.

Jump to

Keyboard shortcuts

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