calendar

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package calendar provides event scheduling with recurrence rules and per-attendee RSVP state — distinct from kit/scheduler (in-process fire-once / cron) by modelling human time semantics: invitations, RSVP states, attendee caps, organiser permissions, named recurrence rules.

Use cases: game guild events, on-call rotations, meeting bookings, scheduled trading rebalances. The package ships an in-memory Manager for tests and a clean interface for PG-backed implementations.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEventNotFound           = errors.New("calendar: event not found")
	ErrInviteNotFound          = errors.New("calendar: invitation not found")
	ErrAtCapacity              = errors.New("calendar: event at attendee capacity")
	ErrCustomRRULENotSupported = errors.New("calendar: RuleCustom requires a consumer-supplied expander")
)

Errors surfaced by the manager.

Functions

This section is empty.

Types

type AttendeeID

type AttendeeID string

EventID, InviteID, and AttendeeID are opaque caller-meaningful identifiers.

type Event

type Event struct {
	ID           EventID
	Organiser    AttendeeID
	Title        string
	Description  string
	Start, End   time.Time
	Recurrence   Recurrence
	MaxAttendees int // 0 = unlimited
	Meta         map[string]any
}

Event is the canonical event entity.

type EventID

type EventID string

EventID, InviteID, and AttendeeID are opaque caller-meaningful identifiers.

type EventOccurrence

type EventOccurrence struct {
	Event Event
	Start time.Time
	End   time.Time
}

EventOccurrence is an expanded recurring-event instance.

type Invitation

type Invitation struct {
	ID          InviteID
	Event       EventID
	Attendee    AttendeeID
	State       RSVPState
	InvitedAt   time.Time
	RespondedAt *time.Time
}

Invitation joins an event with an attendee + RSVP state.

type InviteID

type InviteID string

EventID, InviteID, and AttendeeID are opaque caller-meaningful identifiers.

type Manager

type Manager interface {
	CreateEvent(ctx context.Context, e Event) (EventID, error)
	UpdateEvent(ctx context.Context, e Event) error
	CancelEvent(ctx context.Context, id EventID) error
	GetEvent(ctx context.Context, id EventID) (Event, error)

	Invite(ctx context.Context, eventID EventID, attendees ...AttendeeID) ([]Invitation, error)
	Respond(ctx context.Context, invite InviteID, state RSVPState) error
	Uninvite(ctx context.Context, invite InviteID) error
	Invitations(ctx context.Context, eventID EventID) ([]Invitation, error)

	Occurrences(ctx context.Context, id EventID, from, to time.Time) ([]time.Time, error)
	Upcoming(ctx context.Context, attendee AttendeeID, within time.Duration) ([]EventOccurrence, error)
}

Manager is the canonical surface; the in-memory implementation satisfies it. PG-backed adapters are pluggable behind the same signature.

type MemoryConfig

type MemoryConfig struct {
	Clock func() time.Time
}

MemoryConfig configures MemoryManager.

type MemoryManager

type MemoryManager struct {
	// contains filtered or unexported fields
}

MemoryManager is an in-process Manager. Goroutine-safe.

func NewMemoryManager

func NewMemoryManager(cfg MemoryConfig) *MemoryManager

NewMemoryManager constructs a MemoryManager.

func (*MemoryManager) CancelEvent

func (m *MemoryManager) CancelEvent(_ context.Context, id EventID) error

CancelEvent removes the event and all of its invitations.

func (*MemoryManager) CreateEvent

func (m *MemoryManager) CreateEvent(_ context.Context, e Event) (EventID, error)

CreateEvent stores e. If e.ID is empty, a fresh id is assigned.

func (*MemoryManager) GetEvent

func (m *MemoryManager) GetEvent(_ context.Context, id EventID) (Event, error)

GetEvent fetches an event by id.

func (*MemoryManager) Invitations

func (m *MemoryManager) Invitations(_ context.Context, eventID EventID) ([]Invitation, error)

Invitations returns every invitation for an event.

func (*MemoryManager) Invite

func (m *MemoryManager) Invite(_ context.Context, eventID EventID, attendees ...AttendeeID) ([]Invitation, error)

Invite issues invitations to one or more attendees. Honors MaxAttendees.

func (*MemoryManager) Occurrences

func (m *MemoryManager) Occurrences(_ context.Context, id EventID, from, to time.Time) ([]time.Time, error)

Occurrences expands a recurring event between [from, to].

func (*MemoryManager) Respond

func (m *MemoryManager) Respond(_ context.Context, invite InviteID, state RSVPState) error

Respond updates an invitation's RSVP state.

func (*MemoryManager) Uninvite

func (m *MemoryManager) Uninvite(_ context.Context, invite InviteID) error

Uninvite removes an invitation.

func (*MemoryManager) Upcoming

func (m *MemoryManager) Upcoming(ctx context.Context, attendee AttendeeID, within time.Duration) ([]EventOccurrence, error)

Upcoming returns occurrences within [now, now+within] for events where attendee has an accepted/tentative invitation.

func (*MemoryManager) UpdateEvent

func (m *MemoryManager) UpdateEvent(_ context.Context, e Event) error

UpdateEvent replaces an existing event.

type RSVPState

type RSVPState uint8

RSVPState tracks an attendee's response.

const (
	RSVPInvited RSVPState = iota
	RSVPAccepted
	RSVPDeclined
	RSVPTentative
	RSVPOut
)

type Recurrence

type Recurrence struct {
	Rule  RuleKind
	Until *time.Time // optional end date (inclusive)
	Count *int       // optional max occurrence count (counted from Start)
	RRule string     // only used when Rule == RuleCustom
}

Recurrence describes how an event repeats.

type RuleKind

type RuleKind uint8

RuleKind enumerates supported recurrence patterns. The Custom rule requires Recurrence.RRule to be set to a caller-parsed iCal RRULE string — the kit doesn't bundle an RRULE parser.

const (
	RuleNever RuleKind = iota
	RuleDaily
	RuleWeekly
	RuleBiweekly
	RuleMonthly
	RuleCustom
)

Jump to

Keyboard shortcuts

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