schedule

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultWorkingHoursSchedule = Schedule{
	Days:      []time.Weekday{time.Monday, time.Tuesday, time.Wednesday, time.Thursday, time.Friday},
	StartHour: 9,
	EndHour:   17,
}

DefaultWorkingHoursSchedule is a standard Monday-Friday 9-17 working hours schedule.

Functions

This section is empty.

Types

type CompositeSchedule added in v0.0.9

type CompositeSchedule struct {
	Groups   []DaySchedule
	Location *time.Location
}

CompositeSchedule combines multiple DaySchedule groups into one. A day matches if any group matches; slots are the union of all matching groups.

func (CompositeSchedule) MatchesDay added in v0.0.9

func (cs CompositeSchedule) MatchesDay(t time.Time) bool

func (CompositeSchedule) PrevMatchingDay added in v0.0.9

func (cs CompositeSchedule) PrevMatchingDay(from time.Time) time.Time

func (CompositeSchedule) SlotsForDay added in v0.0.9

func (cs CompositeSchedule) SlotsForDay(day time.Time) []TimeSlot

type DaySchedule added in v0.0.9

type DaySchedule interface {
	MatchesDay(t time.Time) bool
	SlotsForDay(day time.Time) []TimeSlot
	PrevMatchingDay(from time.Time) time.Time
}

DaySchedule is the common interface for schedule types that can produce per-day time slots and navigate matching days.

type DaySlot added in v0.0.9

type DaySlot struct {
	Start TimeOfDay
	End   TimeOfDay
}

DaySlot represents a continuous time window within a day, possibly crossing midnight.

type MultiSlotSchedule added in v0.0.9

type MultiSlotSchedule struct {
	Days     []time.Weekday
	DaySlots []DaySlot
	Location *time.Location
}

MultiSlotSchedule defines multiple disjoint time windows per day.

func (MultiSlotSchedule) MatchesDay added in v0.0.9

func (ms MultiSlotSchedule) MatchesDay(t time.Time) bool

MatchesDay returns true if t's weekday is one of the schedule's days.

func (MultiSlotSchedule) PrevMatchingDay added in v0.0.9

func (ms MultiSlotSchedule) PrevMatchingDay(from time.Time) time.Time

PrevMatchingDay finds the previous day matching the schedule.

func (MultiSlotSchedule) SlotsForDay added in v0.0.9

func (ms MultiSlotSchedule) SlotsForDay(day time.Time) []TimeSlot

SlotsForDay generates time slots for a single day from multi-slot config. Cross-midnight slots (hour >= 24) naturally extend into the next calendar day.

type Schedule

type Schedule struct {
	Days      []time.Weekday // e.g., [Mon, Tue, Wed, Thu, Fri]
	StartHour int            // e.g., 9
	EndHour   int            // e.g., 17
	Gaps      []TimeRange    // optional gaps (e.g., lunch: [{12, 13}])
	Location  *time.Location // timezone
}

Schedule defines working hours for a set of days.

func (Schedule) AvailableMinutes

func (s Schedule) AvailableMinutes(day time.Time) int

AvailableMinutes returns total available minutes in schedule for a day.

func (Schedule) Contains

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

Contains returns true if t matches both the day and time of the schedule.

func (Schedule) MatchesDay

func (s Schedule) MatchesDay(t time.Time) bool

MatchesDay returns true if t's weekday is one of the schedule's days.

func (Schedule) MatchesTime

func (s Schedule) MatchesTime(t time.Time) bool

MatchesTime returns true if t's time-of-day is within schedule hours (excluding gaps).

func (Schedule) NextMatchingDay

func (s Schedule) NextMatchingDay(from time.Time) time.Time

NextMatchingDay finds the next day matching the schedule.

func (Schedule) NextNonMatchingDay

func (s Schedule) NextNonMatchingDay(from time.Time) time.Time

NextNonMatchingDay finds the next day not matching the schedule.

func (Schedule) PrevMatchingDay

func (s Schedule) PrevMatchingDay(from time.Time) time.Time

PrevMatchingDay finds the previous day matching the schedule. e.g., called on Sunday -> returns Friday (for Mon-Fri schedule).

func (Schedule) PrevNonMatchingDay

func (s Schedule) PrevNonMatchingDay(from time.Time) time.Time

PrevNonMatchingDay finds the previous day not matching the schedule. e.g., called on Monday -> returns Sunday (for Mon-Fri schedule).

func (Schedule) SlotsForDay

func (s Schedule) SlotsForDay(day time.Time) []TimeSlot

SlotsForDay generates hour slots for a single day If gaps are configured, returns multiple slots (split by gaps).

func (Schedule) SlotsForRange

func (s Schedule) SlotsForRange(from, to time.Time) []TimeSlot

SlotsForRange generates slots across multiple days.

type TimeOfDay added in v0.0.9

type TimeOfDay struct {
	Hour   int // 0-35
	Minute int // 0-59
}

TimeOfDay represents a time-of-day with minute precision. Hour can be >= 24 for cross-midnight support (e.g., 26:00 = 2AM next day).

func (TimeOfDay) ToDuration added in v0.0.9

func (t TimeOfDay) ToDuration() time.Duration

ToDuration converts TimeOfDay to a duration from midnight.

type TimeRange

type TimeRange struct {
	StartHour int // e.g., 12
	EndHour   int // e.g., 13
}

TimeRange represents a time range within a day (hour-based).

type TimeSlot

type TimeSlot struct {
	Start time.Time
	End   time.Time
}

TimeSlot represents a continuous time range.

func (TimeSlot) Duration

func (ts TimeSlot) Duration() time.Duration

Duration returns the duration of the slot.

Jump to

Keyboard shortcuts

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