Documentation
¶
Overview ¶
Package recurrence computes next occurrences of weekly recurring event patterns expressed as JSON. A pattern names a day of the week and a daily start time; occurrence math is performed in a caller-supplied time zone so results stay correct across daylight-saving-time transitions.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrEmptyPattern = errors.New("recurrence: empty pattern") ErrUnknownDay = errors.New("recurrence: unknown day_of_week") ErrTimeOutOfRange = errors.New("recurrence: time out of range") ErrInvalidTimeFormat = errors.New("recurrence: expected HH:MM format") )
Sentinel errors for recurrence operations.
Functions ¶
func NextOccurrence ¶
NextOccurrence computes the next occurrence of a recurring event from `after`, in the given timezone. Returns the date/time of the next occurrence with the pattern's start_time applied.
Rules:
- If `after` is on the target day_of_week AND before start_time, returns today at start_time.
- Otherwise, returns the next future instance of the day_of_week at start_time.
Always computes in the provided timezone to handle DST correctly.
Types ¶
type Pattern ¶
type Pattern struct {
DayOfWeek string `json:"day_of_week"` // "monday", "tuesday", ..., "sunday"
StartTime string `json:"start_time"` // "HH:MM" 24-hour
EndTime string `json:"end_time"` // "HH:MM" 24-hour
}
Pattern describes a weekly recurring event expressed as JSON. Example: {"day_of_week":"friday","start_time":"17:00","end_time":"22:00"}
func ParsePattern ¶
func ParsePattern(raw json.RawMessage) (*Pattern, error)
ParsePattern parses a JSON recurrence pattern.