Documentation ¶
Index ¶
- type DB
- func (db *DB) Add(ctx context.Context, r *Rule) (*Rule, error)
- func (db *DB) CreateRuleTx(ctx context.Context, tx *sql.Tx, r *Rule) (*Rule, error)
- func (db *DB) Delete(ctx context.Context, ruleID string) error
- func (db *DB) DeleteByTarget(ctx context.Context, scheduleID string, target assignment.Target) error
- func (db *DB) DeleteManyTx(ctx context.Context, tx *sql.Tx, ruleIDs []string) error
- func (db *DB) DeleteTx(ctx context.Context, tx *sql.Tx, ruleID string) error
- func (db *DB) FindAll(ctx context.Context, scheduleID string) ([]Rule, error)
- func (db *DB) FindAllTx(ctx context.Context, tx *sql.Tx, scheduleID string) ([]Rule, error)
- func (db *DB) FindAllWithUsers(ctx context.Context, scheduleID string) ([]Rule, error)
- func (db *DB) FindByTargetTx(ctx context.Context, tx *sql.Tx, scheduleID string, target assignment.Target) ([]Rule, error)
- func (db *DB) FindOne(ctx context.Context, ruleID string) (*Rule, error)
- func (db *DB) FindScheduleID(ctx context.Context, ruleID string) (string, error)
- func (db *DB) Update(ctx context.Context, r *Rule) error
- func (db *DB) UpdateTx(ctx context.Context, tx *sql.Tx, r *Rule) error
- type ReadStore
- type Rule
- type ScheduleTriggerFunc
- type Store
- type WeekdayFilter
- func (f WeekdayFilter) Day(d time.Weekday) bool
- func (f WeekdayFilter) DaysSince(d time.Weekday, enabled bool) int
- func (f WeekdayFilter) DaysUntil(d time.Weekday, enabled bool) int
- func (f WeekdayFilter) NextActive(t time.Time) time.Time
- func (f WeekdayFilter) NextInactive(t time.Time) time.Time
- func (f *WeekdayFilter) Scan(src interface{}) error
- func (f *WeekdayFilter) SetDay(d time.Weekday, enabled bool)
- func (f WeekdayFilter) StartTime(t time.Time) time.Time
- func (f WeekdayFilter) String() string
- func (f WeekdayFilter) Value() (driver.Value, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
func (*DB) CreateRuleTx ¶
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) FindAllWithUsers ¶
func (*DB) FindByTargetTx ¶
func (*DB) FindScheduleID ¶
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 timeutil.Clock `json:"start"` End timeutil.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 ¶
AlwaysActive will return true if the rule will always be active.
func (Rule) EndTime ¶
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.
If the rule is always active, or never active, it returns a zero time.
func (Rule) IsActive ¶
IsActive determines if the rule is active in the given moment in time, in the location of t.
func (Rule) NeverActive ¶
NeverActive returns true if the rule will never be active.
func (Rule) StartTime ¶
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.
It may break when processing a timezone where daylight savings repeats or skips ahead at midnight.
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 EveryDay ¶ added in v0.27.0
func EveryDay() WeekdayFilter
EveryDay returns a WeekdayFilter that is permanently active.
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) NextActive ¶ added in v0.27.0
func (f WeekdayFilter) NextActive(t time.Time) time.Time
NextActive returns the next time, at midnight, from t that is active.
If the filter is active every day or no days, zero time is returned. Otherwise the returned value will always be in the future.
func (WeekdayFilter) NextInactive ¶ added in v0.27.0
func (f WeekdayFilter) NextInactive(t time.Time) time.Time
NextInactive returns the next time, at midnight, from t that is no longer active.
If the filter is active every day or no days, zero time is returned. Otherwise the returned value will always be in the future.
func (*WeekdayFilter) Scan ¶ added in v0.24.0
func (f *WeekdayFilter) Scan(src interface{}) error
Scan scans the WeekdayFilter from a DB array of bool.
func (*WeekdayFilter) SetDay ¶
func (f *WeekdayFilter) SetDay(d time.Weekday, enabled bool)
SetDay will update the filter for the given weekday.
func (WeekdayFilter) StartTime ¶ added in v0.27.0
func (f WeekdayFilter) StartTime(t time.Time) time.Time
StartTime returns midnight of the day the filter became active, from the perspective of t.
If the filter is active every day or no days, zero time is returned. If the current day is not active, zero time is returned.
func (WeekdayFilter) String ¶
func (f WeekdayFilter) String() string
String returns a string representation of the WeekdayFilter.