schedule

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 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 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 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