Documentation ¶
Index ¶
- Constants
- Variables
- func SlotKeys(slots ...WeekdayTimeSlot) []int
- type Calendar
- type CalendarMap
- type Clock
- func (c Clock) Add(minutes int) Clock
- func (c Clock) After(c2 Clock) bool
- func (c Clock) Before(c2 Clock) bool
- func (c Clock) Equal(c2 Clock) bool
- func (c Clock) Hour() int
- func (c Clock) IsZero() bool
- func (c Clock) MarshalJSON() ([]byte, error)
- func (c Clock) Minute() int
- func (c Clock) Nanosecond() int
- func (c Clock) Pointer() *Clock
- func (c *Clock) Scan(src interface{}) error
- func (c Clock) Second() int
- func (c Clock) String() string
- func (c Clock) Subtract(minutes int) Clock
- func (c Clock) ToDuration() time.Duration
- func (c Clock) ToTime(date Date, loc *time.Location) time.Time
- func (c *Clock) UnmarshalJSON(b []byte) error
- func (c Clock) Value() (driver.Value, error)
- type Date
- func (d Date) AddDate(year, month, day int) Date
- func (d Date) After(date Date) bool
- func (d Date) Before(date Date) bool
- func (d *Date) Date() *Date
- func (d Date) Day() int
- func (d Date) Equal(date Date) bool
- func (d *Date) IsZero() bool
- func (d Date) MarshalJSON() ([]byte, error)
- func (d Date) MarshalText() (text []byte, err error)
- func (d Date) Month() time.Month
- func (d Date) Next() Date
- func (d Date) Pointer() *Date
- func (d *Date) Scan(src interface{}) error
- func (d Date) String() string
- func (d Date) Sub(date Date) int
- func (d Date) ToTime() time.Time
- func (d *Date) UnmarshalJSON(bytes []byte) error
- func (d *Date) UnmarshalText(text []byte) error
- func (d Date) Value() (driver.Value, error)
- func (d Date) Weekday() Weekday
- func (d Date) Year() int
- type DateRange
- func (dr DateRange) ContainsDate(date Date) bool
- func (dr DateRange) DayCount() int
- func (dr DateRange) Equal(dr2 DateRange) bool
- func (dr DateRange) Exceeds(parentDR DateRange) bool
- func (dr DateRange) HasDays() bool
- func (dr DateRange) IsZero() bool
- func (dr DateRange) Merge(dr2 DateRange) DateRange
- func (dr DateRange) Overlaps(dr2 DateRange) bool
- func (dr DateRange) String() string
- func (dr DateRange) Validate() error
- func (dr DateRange) WithFrom(d Date) DateRange
- func (dr DateRange) WithUntil(d Date) DateRange
- type Schedule
- func (s Schedule) From() Date
- func (s Schedule) HasTimeSlots() bool
- func (s Schedule) IsEmpty() bool
- func (s Schedule) Merge(schedules ...Schedule) Schedule
- func (s Schedule) Until() *Date
- func (s Schedule) WithDateRange(dateRange DateRange) Schedule
- func (s Schedule) WithFrom(from Date) Schedule
- func (s Schedule) WithTimeSlots(slots ...WeekdayTimeSlot) Schedule
- func (s Schedule) WithUntil(until Date) Schedule
- type TimeSlot
- type Weekday
- func (w Weekday) MarshalJSON() ([]byte, error)
- func (w Weekday) MarshalText() (text []byte, err error)
- func (w Weekday) Next() Weekday
- func (w *Weekday) Scan(src interface{}) error
- func (w Weekday) String() string
- func (w *Weekday) UnmarshalJSON(b []byte) error
- func (w *Weekday) UnmarshalText(b []byte) error
- func (w Weekday) Value() (driver.Value, error)
- type WeekdayTimeSlot
- func MergeWeekdayTimeSlots(a, b []WeekdayTimeSlot) []WeekdayTimeSlot
- func NewWeekdayAllDayTimeSlot(day Weekday) WeekdayTimeSlot
- func NewWeekdayTimeSlot(day Weekday, slot TimeSlot) WeekdayTimeSlot
- func SortWeekdayTimeSlots(wtsSlice ...WeekdayTimeSlot) []WeekdayTimeSlot
- func UniqueWeekdayTimeSlots(wtsSlice ...WeekdayTimeSlot) []WeekdayTimeSlot
- func WeekdayTimeSlotFromInt(wtsInt int) WeekdayTimeSlot
- func WeekdayTimeSlotFromString(wtsString string) WeekdayTimeSlot
- func (s WeekdayTimeSlot) Duration() time.Duration
- func (s WeekdayTimeSlot) End() Clock
- func (s WeekdayTimeSlot) Equal(s2 WeekdayTimeSlot) bool
- func (s WeekdayTimeSlot) IsAllDay() bool
- func (s WeekdayTimeSlot) MarshalJSON() ([]byte, error)
- func (s WeekdayTimeSlot) Minutes() int
- func (s WeekdayTimeSlot) OverlapsWith(wts2 WeekdayTimeSlot) bool
- func (s *WeekdayTimeSlot) Scan(src interface{}) error
- func (s WeekdayTimeSlot) Slot() TimeSlot
- func (s WeekdayTimeSlot) Start() Clock
- func (s WeekdayTimeSlot) String() string
- func (s WeekdayTimeSlot) ToInt() int
- func (s WeekdayTimeSlot) ToString() string
- func (s *WeekdayTimeSlot) UnmarshalJSON(data []byte) error
- func (s WeekdayTimeSlot) Value() (driver.Value, error)
- func (s WeekdayTimeSlot) Weekday() Weekday
- type WeekdayTimeSlotMap
- func (w WeekdayTimeSlotMap) Add(day Weekday, slots ...TimeSlot) WeekdayTimeSlotMap
- func (w WeekdayTimeSlotMap) AddTimeSlot(day Weekday, start, end Clock) WeekdayTimeSlotMap
- func (w WeekdayTimeSlotMap) Has(day Weekday, slot TimeSlot) bool
- func (w WeekdayTimeSlotMap) TimeSlots(day Weekday) []TimeSlot
- func (w WeekdayTimeSlotMap) ToWeekdayTimeSlots() []WeekdayTimeSlot
Constants ¶
const ( Sunday = Weekday(time.Sunday) Monday = Weekday(time.Monday) Tuesday = Weekday(time.Tuesday) Wednesday = Weekday(time.Wednesday) Thursday = Weekday(time.Thursday) Friday = Weekday(time.Friday) Saturday = Weekday(time.Saturday) )
const InfDays = math.MaxInt32
InfDays represents an infinite number of days MaxInt32 days is over 5.8 million years we are not using a negative number because someone may check DayCount() > 0 to know if it has days or not
Variables ¶
Functions ¶
func SlotKeys ¶
func SlotKeys(slots ...WeekdayTimeSlot) []int
Types ¶
type Calendar ¶
type Calendar struct {
// contains filtered or unexported fields
}
func NewCalendar ¶
func (Calendar) ByDate ¶
func (c Calendar) ByDate(limit Date) CalendarMap
func (Calendar) WithSchedules ¶
WithSchedules appends schedules to existing Calendar
type CalendarMap ¶
type CalendarMap map[Date][]WeekdayTimeSlot
func (CalendarMap) GetTimeslots ¶
func (cm CalendarMap) GetTimeslots() []WeekdayTimeSlot
func (CalendarMap) HasDate ¶
func (cm CalendarMap) HasDate(date Date) bool
type Clock ¶
type Clock struct {
// contains filtered or unexported fields
}
Clock contains minute in a day
func ParseClock ¶
ParseClock takes a string of hours:minutes such as "15:30"
func (Clock) MarshalJSON ¶
MarshalJSON marshals the enum as a quoted json string
func (Clock) Nanosecond ¶
func (*Clock) Scan ¶
Scan implements sql.Scanner so that Scan will be scanned correctly from storage
func (Clock) ToDuration ¶
func (*Clock) UnmarshalJSON ¶
UnmarshalJSON unmashals a quoted json string
type Date ¶
type Date struct {
// contains filtered or unexported fields
}
func NewDateFromTime ¶
func ZeroDate ¶
func ZeroDate() *Date
ZeroDate is just a zero value Date it is good for json decoding and sql scanning
func (Date) MarshalJSON ¶
func (Date) MarshalText ¶
func (Date) Sub ¶
Sub subtracts two dates, returning the number of days between
today.Sub(today) = 0 today.Sub(yesterday) = 1 yesterday.Sub(today) = -1
func (*Date) UnmarshalJSON ¶
func (*Date) UnmarshalText ¶
type DateRange ¶
DateRange represents a set of days this set includes the From date and the Until date from Jan1 until Jan1 is one day from Jan1 until Jan2 is two days when Until is nil it means forever
func NewDateRange ¶
func NewDateRange() DateRange
func NewDateRangeUntil ¶
func ZeroDateRange ¶
func ZeroDateRange() DateRange
func (DateRange) ContainsDate ¶
func (DateRange) DayCount ¶
DayCount is the number of days in range when until is nil then the range is infinite from today until today has one day in range from today until tomorrow has two days in range
type Schedule ¶
type Schedule struct { DateRange DateRange TimeSlots []WeekdayTimeSlot }
func NewSchedule ¶
func NewSchedule(dr DateRange, slots ...WeekdayTimeSlot) Schedule
func (Schedule) HasTimeSlots ¶
func (Schedule) IsEmpty ¶
IsEmpty means there are either no days in range or there are no timeslots, therefore nothing on schedule
func (Schedule) Merge ¶
Merge does a merge on both the schedule dateRanges and the timeslots
The intended use for this is to merge a parent schedule with a sub schedule the sub schedule is a subset of the parent, however it may have all-day entries which allow for config on "any" timeslots for that day if timeslots exist on only the parent, they are excluded if timeslots exist on only the child, they are invalid, and therefore excluded
dateRange
a merged dateRange is where they intersect - ex: jan01-jan30 merged with jan15-feb15 results in jan15-jan30
timeslots
are only kept in a merge when they exist in all schedules without conflicting exception is when one schedule has an all day timeslot and another specific timeslots this results in the specific timeslots being kept in favor of the all day - ex: Mon7-8,Tues8-9,Wed merged with Mon7-8,Tues6-7,Wed7-8 results in Mon7-8,Wed7-8 Tues809,Tues6-7 were excluded because they only exist in one schedule Wed7-8 was included because the other schedule was for Wed all day
see TestSchedulesMerge for a good example
func (Schedule) WithDateRange ¶
func (Schedule) WithTimeSlots ¶
func (s Schedule) WithTimeSlots(slots ...WeekdayTimeSlot) Schedule
type TimeSlot ¶
func NewTimeSlot ¶
func ParseTimeSlot ¶
type Weekday ¶
Weekday exists only because time.Weekday does not serialize to a string so models.Weekday will be a string when in JSON or database
func NewWeekday ¶
NewWeekday converts a string name to a Weekday object to get Weekday from time.Weekday simply type assert ex: models.Weekday(time.Monday)
func ParseWeekday ¶
func TodayWeekday ¶
func TodayWeekday() Weekday
func (Weekday) MarshalJSON ¶
MarshalJSON marshals the enum as a quoted json string
func (Weekday) MarshalText ¶
func (*Weekday) Scan ¶
Scan implements sql.Scanner so that Scan will be scanned correctly from storage
func (*Weekday) UnmarshalJSON ¶
func (*Weekday) UnmarshalText ¶
type WeekdayTimeSlot ¶
type WeekdayTimeSlot struct {
// contains filtered or unexported fields
}
func MergeWeekdayTimeSlots ¶
func MergeWeekdayTimeSlots(a, b []WeekdayTimeSlot) []WeekdayTimeSlot
func NewWeekdayAllDayTimeSlot ¶
func NewWeekdayAllDayTimeSlot(day Weekday) WeekdayTimeSlot
func NewWeekdayTimeSlot ¶
func NewWeekdayTimeSlot(day Weekday, slot TimeSlot) WeekdayTimeSlot
func SortWeekdayTimeSlots ¶
func SortWeekdayTimeSlots(wtsSlice ...WeekdayTimeSlot) []WeekdayTimeSlot
func UniqueWeekdayTimeSlots ¶
func UniqueWeekdayTimeSlots(wtsSlice ...WeekdayTimeSlot) []WeekdayTimeSlot
UniqueWeekdayTimeSlots sorts and removes duplicates
func WeekdayTimeSlotFromInt ¶
func WeekdayTimeSlotFromInt(wtsInt int) WeekdayTimeSlot
func WeekdayTimeSlotFromString ¶
func WeekdayTimeSlotFromString(wtsString string) WeekdayTimeSlot
func (WeekdayTimeSlot) Duration ¶
func (s WeekdayTimeSlot) Duration() time.Duration
func (WeekdayTimeSlot) End ¶
func (s WeekdayTimeSlot) End() Clock
func (WeekdayTimeSlot) Equal ¶
func (s WeekdayTimeSlot) Equal(s2 WeekdayTimeSlot) bool
func (WeekdayTimeSlot) IsAllDay ¶
func (s WeekdayTimeSlot) IsAllDay() bool
func (WeekdayTimeSlot) MarshalJSON ¶ added in v0.1.7
func (s WeekdayTimeSlot) MarshalJSON() ([]byte, error)
func (WeekdayTimeSlot) Minutes ¶
func (s WeekdayTimeSlot) Minutes() int
func (WeekdayTimeSlot) OverlapsWith ¶
func (s WeekdayTimeSlot) OverlapsWith(wts2 WeekdayTimeSlot) bool
func (*WeekdayTimeSlot) Scan ¶ added in v0.1.7
func (s *WeekdayTimeSlot) Scan(src interface{}) error
func (WeekdayTimeSlot) Slot ¶
func (s WeekdayTimeSlot) Slot() TimeSlot
func (WeekdayTimeSlot) Start ¶
func (s WeekdayTimeSlot) Start() Clock
func (WeekdayTimeSlot) String ¶
func (s WeekdayTimeSlot) String() string
func (WeekdayTimeSlot) ToInt ¶
func (s WeekdayTimeSlot) ToInt() int
ToInt stores the object in binary 3 bits for day, 11 bits for start, 11 bits for end this could be used to check equality or sorting
func (WeekdayTimeSlot) ToString ¶
func (s WeekdayTimeSlot) ToString() string
func (*WeekdayTimeSlot) UnmarshalJSON ¶ added in v0.1.7
func (s *WeekdayTimeSlot) UnmarshalJSON(data []byte) error
func (WeekdayTimeSlot) Value ¶ added in v0.1.7
func (s WeekdayTimeSlot) Value() (driver.Value, error)
func (WeekdayTimeSlot) Weekday ¶
func (s WeekdayTimeSlot) Weekday() Weekday
type WeekdayTimeSlotMap ¶
func NewWeekdayTimeSlotMap ¶
func NewWeekdayTimeSlotMap() WeekdayTimeSlotMap
func WeekdayTimeSlotMapFromSlice ¶
func WeekdayTimeSlotMapFromSlice(wtsSlice []WeekdayTimeSlot) WeekdayTimeSlotMap
func (WeekdayTimeSlotMap) Add ¶
func (w WeekdayTimeSlotMap) Add(day Weekday, slots ...TimeSlot) WeekdayTimeSlotMap
func (WeekdayTimeSlotMap) AddTimeSlot ¶
func (w WeekdayTimeSlotMap) AddTimeSlot(day Weekday, start, end Clock) WeekdayTimeSlotMap
func (WeekdayTimeSlotMap) TimeSlots ¶
func (w WeekdayTimeSlotMap) TimeSlots(day Weekday) []TimeSlot
func (WeekdayTimeSlotMap) ToWeekdayTimeSlots ¶
func (w WeekdayTimeSlotMap) ToWeekdayTimeSlots() []WeekdayTimeSlot