shiftpad

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2023 License: MIT Imports: 14 Imported by: 0

README

shiftpad

Like Etherpad, but for shift schedules.

Documentation

Index

Constants

View Source
const MaxFuture = 180 * 24 * time.Hour

MaxFuture specifies how far in the future shifts can be created and edited, and the expiry time of pads.

Variables

View Source
var ErrUnauthorized = errors.New("unauthorized")
View Source
var SystemLocation *time.Location = GetSystemLocation()

Functions

func CheckBeginEnd

func CheckBeginEnd(begin, end time.Time, pastAlways bool, future time.Duration) error

CheckBeginEnd checks that begin or end are non-zero, that end is after begin (or end is zero), and that begin and end are not too far in the past and future.

func GetInterval

func GetInterval(repo Repository, pad *Pad, from, to time.Time, location *time.Location) ([]Event, []Shift, error)

weeks can't be split into days because shifts and events may be contained in multiple days then, but we want them just once in a week (or any other interval)

func GetSystemLocation

func GetSystemLocation() *time.Location

GetSystemLocation returns the location linked by /etc/localtime if it is a canonical location, or "Etc/GMT" else.

func Intersect

func Intersect(as, bs []string) []string

func Locations

func Locations(loc string) []string

Locations returns the list of canonical locations plus the given location, which might be a legacy one.

Types

type Auth

type Auth struct {
	Admin            bool
	Edit             []string
	EditAll          bool
	EditRetroAlways  bool
	Expires          string // yyyy-mm-dd
	Note             string
	Take             []string
	TakeAll          bool
	TakeDeadline     string // cronexpr
	TakerName        []string
	TakerNameAll     bool
	ViewTakerContact bool
	ViewTakerName    bool // also visible if contained in Auth.TakerName
}

func DecodeAuth

func DecodeAuth(s string) (Auth, error)

func (Auth) Active

func (auth Auth) Active() bool

Active returns true if an expiry date is set and is not in the past.

func (Auth) CanEdit

func (auth Auth) CanEdit(shiftname string) bool

func (Auth) CanEditShift

func (auth Auth) CanEditShift(shift Shift) bool

When editing a shift, CanEditShift must be called on the original and on the modified shift.

func (Auth) CanEditSomeShift

func (auth Auth) CanEditSomeShift() bool

func (Auth) CanTake

func (auth Auth) CanTake(shiftname string) bool

func (Auth) CanTakeShift

func (auth Auth) CanTakeShift(shift Shift) bool

func (Auth) CanTakerName

func (auth Auth) CanTakerName(shift Shift, name string) bool

func (Auth) Encode

func (auth Auth) Encode() ([]byte, error)

Encode copies the contents of auth into url.Values and encodes them. Note that url.Values are designed for url queries, not url path elements. The only difference is the representation of the space character.

func (Auth) Restrict

func (ref Auth) Restrict(input Auth) Auth

Restricts returns a copy of input which is restricted to a reference Auth. Note that this function is not symmetric and thus not an intersection.

func (Auth) TakerString

func (auth Auth) TakerString(shift Shift) string

TakerString returns a string containing the taker name and taker contact of the given shift, or "taken" if auth.ViewTakerContact and auth.ViewTakerName are false. If the shift is not taken, an empty string is returned.

type AuthPad

type AuthPad struct {
	Auth
	*Pad
}

An AuthPad is a pad with verified authentication.

func Verify

func Verify(pad *Pad, authstr, sig string) (AuthPad, error)

Verify verifies the given base64-encoded signature of the given auth string, decodes the auth string and checks auth.Active().

func (AuthPad) EditShiftNames

func (ap AuthPad) EditShiftNames() []string

EditShiftNames returns the shift names that auth can edit. You must check len(Pad.ShiftNames) > 0 separately.

func (ap AuthPad) Link() string

type Day

type Day struct {
	Begin  time.Time // inclusive
	End    time.Time // exclusive
	Events []Event   // both with and without shifts
	Shifts []Shift   // without an event
}

func GetDay

func GetDay(repo Repository, pad *Pad, date time.Time, location *time.Location) (Day, error)

date must be any time in the day

func (Day) FmtDateTime

func (day Day) FmtDateTime(t time.Time) string

func (Day) FmtDateTimeRange

func (day Day) FmtDateTimeRange(begin, end time.Time) string

func (Day) FmtEventTime

func (day Day) FmtEventTime(event ical.Event) string

func (Day) FmtShiftTime

func (day Day) FmtShiftTime(shift Shift) string

func (Day) Groups

func (day Day) Groups() []Group

Groups returns the events plus an event with empty UID, which contains all shifts without an event.

type Event

type Event struct {
	ical.Event
	Shifts []Shift
}

type Group

type Group struct {
	*ical.Event // can be nil
	Shifts      []Shift
}

Group is used for displaying. It can represent an event or a bunch of independent shifts.

type Pad

type Pad struct {
	ID string

	Description string
	ICalOverlay string
	LastUpdated string         // yyyy-mm-dd, update on take and edit (updating on view would cost some performance)
	Location    *time.Location // must not be nil
	Name        string
	PrivateKey  ed25519.PrivateKey
	ShiftNames  []string
}

func NewPad

func NewPad() (Pad, error)

type Repository

type Repository interface {
	GetICalFeedCache(url string) *ical.FeedCache
	GetShifts(pad *Pad, from, to int64) ([]Shift, error) // begin: from inclusive, to exclusive
	GetShiftsByEvent(pad *Pad, eventUID string) ([]Shift, error)
}

type Shift

type Shift struct {
	ID           int
	Modified     time.Time // used in ical export
	Name         string    // matched against Pad.ShiftNames
	Note         string    // free text, not matched
	EventUID     string
	Begin        time.Time // Begin.IsZero() means undefined
	End          time.Time // End.IsZero() means undefined
	TakerName    string
	TakerContact string
}

func (Shift) AfterDeadline

func (shift Shift) AfterDeadline(deadline string) bool

func (Shift) BeginTime

func (shift Shift) BeginTime() time.Time

BeginTime returns shift.Begin if it is not zero, or shift.End else.

func (Shift) EndTime

func (shift Shift) EndTime() time.Time

EndTime returns shift.End if it is not zero, or shift.Begin else.

func (Shift) Over

func (shift Shift) Over() bool

func (Shift) Taken

func (shift Shift) Taken() bool

type Week

type Week struct {
	Begin time.Time
	End   time.Time
	Days  [7]*Day
}

func GetWeek

func GetWeek(repo Repository, pad *Pad, year, week int, location *time.Location) (Week, error)

date must be any time in the week

Directories

Path Synopsis
cmd
Package sqlite stores pads and shifts in a SQLite database.
Package sqlite stores pads and shifts in a SQLite database.

Jump to

Keyboard shortcuts

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