recurrence

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2026 License: MIT Imports: 5 Imported by: 0

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

View Source
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

func NextOccurrence(raw json.RawMessage, after time.Time, tz *time.Location) (time.Time, error)

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.

Jump to

Keyboard shortcuts

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