calendar

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package calendar reads iCalendar events and expands their occurrences (docs/design/pim.md, Calendars; ADR-0018).

Index

Constants

This section is empty.

Variables

View Source
var ErrWholeSeries = errors.New("calendar: from its first occurrence, the change takes the whole series")

ErrWholeSeries is DeleteOccurrence's answer to All Future Events from a series' first occurrence: that deletes the series, so its object.

Functions

func DeleteOccurrence

func DeleteOccurrence(src []byte, recurrenceID string, scope Scope, now time.Time) ([]byte, error)

DeleteOccurrence deletes one occurrence (ScopeThis) or the series from it on (ScopeFuture). Deleting a whole series deletes its object, which is not a patch.

func KeepOverrides

func KeepOverrides(restored, current []byte, now time.Time) ([]byte, error)

KeepOverrides is restored with a plain override, made from its master as This Event makes one, for each occurrence that current overrides and restored does not. Google's CalDAV keeps an exception its PUT leaves out, so a restore written there must reset the exception instead.

func LocalZone

func LocalZone() *time.Location

LocalZone is the system's zone under its IANA name, which writes to Graph and the editor's defaults name: $TZ when it names a zone, else the system's setting (the /etc/localtime link on Linux, the registry's time zone on Windows, through the Windows zone table). time.Local, whose name is "Local", when neither names one.

func MaxSequence

func MaxSequence(src []byte) int

MaxSequence is the highest SEQUENCE among the first VCALENDAR's VEVENTs; 0 when none has one or the source does not parse.

func NewEvent

func NewEvent(uid string, c EventChange, now time.Time) ([]byte, error)

NewEvent writes a calendar object holding one new VEVENT, and the VTIMEZONE of its zone.

func NewTodo

func NewTodo(uid string, c TodoChange, parentUID string, now time.Time) []byte

NewTodo writes a calendar object holding one new VTODO, a subtask of parentUID when it is set.

func PatchEvent

func PatchEvent(src []byte, c EventChange, now time.Time) ([]byte, error)

PatchEvent applies c to the single event, or the master of the series, in src: its VEVENT without RECURRENCE-ID, rewriting only the lines c touches (ADR-0018, ADR-0030, ADR-0033).

func PatchOccurrence

func PatchOccurrence(src []byte, recurrenceID string, scope Scope, c EventChange, newUID string, now time.Time) (patched, split []byte, err error)

PatchOccurrence applies c to one occurrence of the series in src, in scope (ADR-0031). recurrenceID names the occurrence as Parse and Expand do (RecurrenceKey of its original start). For ScopeFuture, split is the new series' object, under newUID; it is nil otherwise.

func PatchTodo

func PatchTodo(src []byte, c TodoChange, now time.Time) ([]byte, error)

PatchTodo applies a change to the first VTODO of src, rewriting only the lines it touches (ADR-0018: the rest stays as the server sent it).

func PersonEmail

func PersonEmail(p contentline.Prop) string

PersonEmail is an organizer's or attendee's address, lowercased: the mailto: value, else the EMAIL parameter (RFC 7986), which iCloud gives the principal URL it writes for the account's own addresses.

func RaiseSequence

func RaiseSequence(src []byte, floor int) ([]byte, error)

RaiseSequence makes every VEVENT's SEQUENCE in src one more than the higher of its own and floor. A source written back over a later version (a restore, ADR-0032) must not go back in SEQUENCE: Google's CalDAV refuses that with 409, and clients read a lower SEQUENCE as outdated.

func RecurrenceKey

func RecurrenceKey(t time.Time, allDay bool) string

RecurrenceKey formats an occurrence's original start as a UTC date for all-day events, or a UTC instant with millisecond precision otherwise.

func VEventRecurrenceID

func VEventRecurrenceID(cal, vevent *contentline.Component, local *time.Location) string

VEventRecurrenceID is the RecurrenceID Parse gives vevent, a VEVENT of the VCALENDAR cal: "" for a single event or a series' master. local reads floating times; nil means time.Local.

func VTimezone

func VTimezone(name string, from time.Time, eol string) (string, error)

VTimezone writes the VTIMEZONE of an IANA zone for events from from on (ADR-0033), with lines ending in eol. It walks the zone's transitions from the year before from to 2037 in maild's tzdata. Standard and daylight time are each a component with a yearly RRULE when their transitions keep one (the same month, n-th or last weekday and wall time); otherwise each transition is an RDATE. Transitions between other offsets or under another name are components of their own. A zone without transitions then is one STANDARD.

func WindowsName

func WindowsName(iana string) (string, bool)

WindowsName returns the Windows time zone name whose main IANA zone (CLDR's territory 001) is iana, such as Microsoft Graph takes in timeZone ("America/New_York" is "Eastern Standard Time"). Of two names with the same zone, the first in order wins.

func WindowsZone

func WindowsZone(name string) (string, bool)

WindowsZone returns the IANA zone for a Windows time zone name, such as Outlook writes in TZID ("Eastern Standard Time" is America/New_York).

func ZoneNamed

func ZoneNamed(tzid string, local *time.Location) *time.Location

ZoneNamed returns the zone an Event's TZID names: an IANA zone, UTC, or a fixed offset written UTC±hh:mm; local for "" (floating). A name it cannot read is UTC.

Types

type Alarm

type Alarm struct {
	Action string // display or audio
	// Offset is relative to the occurrence's start, or its end when
	// RelatedEnd; negative is before. Unused when At is set.
	Offset     time.Duration
	RelatedEnd bool
	At         time.Time // an absolute trigger, in UTC; zero for a relative one
}

Alarm is a DISPLAY or AUDIO VALARM.

type Attendee

type Attendee struct {
	Email    string `json:"email"`             // lowercased, without mailto:
	Name     string `json:"name,omitzero"`     // CN
	Role     string `json:"role,omitzero"`     // chair, required, optional, none
	PartStat string `json:"partStat,omitzero"` // needsaction, accepted, declined, tentative, delegated
}

Attendee is an ORGANIZER or ATTENDEE.

type Event

type Event struct {
	UID string
	// RecurrenceID is "" for a single event or a master; for an override,
	// the start of the occurrence it replaces, formatted as RecurrenceKey.
	RecurrenceID string
	Summary      string
	Location     string
	Description  string
	AllDay       bool
	// Start and End: for a timed event, instants in UTC (End exclusive);
	// for an all-day event, midnight UTC of the first day and of the day
	// after the last.
	Start, End time.Time
	// TZID is the IANA zone DTSTART was resolved to: "UTC" for UTC times,
	// "" for floating times and all-day events.
	TZID string
	// Floating is a timed event without a zone, read in Options.Local.
	Floating bool
	// Recurrence is the RRULE, RDATE and EXDATE content lines as written,
	// unfolded and joined by "\n"; "" for an event that is not a series.
	Recurrence  string
	Status      string // confirmed, tentative or cancelled
	Transparent bool   // TRANSP:TRANSPARENT: does not count as busy
	Organizer   *Attendee
	Attendees   []Attendee // without the organizer
	// PartStat is the user's answer when one of Options.UserEmails is an
	// attendee: needsaction, accepted, declined, tentative, delegated; "".
	PartStat string
	Sequence int
	Alarms   []Alarm
	// Zone is the location DTSTART is read in, for expanding the series
	// in its own wall time: the TZID's zone, Options.Local when floating,
	// UTC for UTC and all-day events.
	Zone *time.Location
}

Event is one VEVENT: a single event, a series' master, or an override of one occurrence of a series (RecurrenceID set).

func Parse

func Parse(raw []byte, opts Options) ([]Event, error)

Parse reads usable VEVENTs from the first VCALENDAR, resolving times, people and supported alarms while retaining recurrence content lines.

type EventChange

type EventChange struct {
	Summary     *string    `json:"summary,omitzero"`
	Location    *string    `json:"location,omitzero"`
	Description *string    `json:"description,omitzero"`
	AllDay      *bool      `json:"allDay,omitzero"`
	Start       *time.Time `json:"start,omitzero"` // timed: instants, written in Zone; End after Start
	End         *time.Time `json:"end,omitzero"`
	Zone        *string    `json:"zone,omitzero"`        // an IANA zone name, or UTC
	StartDate   *string    `json:"startDate,omitzero"`   // all-day: YYYY-MM-DD
	EndDate     *string    `json:"endDate,omitzero"`     // all-day: the day after the last
	RRule       *string    `json:"rrule,omitzero"`       // the RRULE value; "" removes RRULE
	Alarms      *[]int     `json:"alarms,omitzero"`      // minutes before the start (negative: after); replaces the DISPLAY and AUDIO alarms
	Transparent *bool      `json:"transparent,omitzero"` // TRANSP:TRANSPARENT, or OPAQUE when false
	// Attendees replaces the invitees (ADR-0035): an address that stays
	// keeps its line, its answer included, with ROLE from Role (required,
	// optional, chair or none; "" is required); a new one gets a line with
	// NEEDS-ACTION and RSVP. The organizer's own ATTENDEE line stays.
	// Organizer is written as ORGANIZER when the event then has invitees
	// and no organizer, which it needs.
	Attendees *[]Attendee `json:"attendees,omitzero"`
	Organizer *Attendee   `json:"organizer,omitzero"`
}

EventChange is a change to an event (calendar.update's EventFields, ADR-0030): nil fields keep their values. A change of timing gives all of it: AllDay, and Start, End and Zone for a timed event or StartDate and EndDate for an all-day one. Its JSON is how a put's payload keeps it, to apply again after a 412.

type Occurrence

type Occurrence struct {
	// Event is the index, in the events given to Expand, of the single
	// event, the series' master, or the override that replaced this
	// occurrence.
	Event int
	// RecurrenceID is RecurrenceKey of the occurrence's original start; ""
	// for a single event.
	RecurrenceID string
	Start, End   time.Time // as Event's: instants, or UTC midnights for all-day
	AllDay       bool
}

Occurrence is one occurrence of an event.

func Expand

func Expand(events []Event, from, to time.Time) ([]Occurrence, error)

Expand returns the occurrences of one calendar object's events that overlap [from, to), ordered by start and event index. Series expand in their own zones, with overrides replacing their original occurrences.

type Options

type Options struct {
	// Local is the zone of floating times; nil means time.Local.
	Local *time.Location
	// UserEmails are the account's own addresses, lowercased: the attendee
	// with one of them is the user.
	UserEmails []string
}

Options say how to read an object's events.

type Scope

type Scope int

Scope says what a change to one occurrence of a series changes (ADR-0031).

const (
	ScopeThis   Scope = iota // the occurrence: an override, or an EXDATE when deleting
	ScopeFuture              // the occurrence and those after it: the series splits
	ScopeAll                 // the whole series: its master
)

The scopes, as calendar.update and calendar.delete take them.

type Todo

type Todo struct {
	UID string
	// ParentUID is RELATED-TO with RELTYPE=PARENT or no RELTYPE; "" when none.
	ParentUID   string
	Summary     string
	Description string
	// Due is DUE's date, YYYY-MM-DD (a DATE-TIME's date in Options.Local), or "".
	Due string
	// Completed is STATUS:COMPLETED, or a COMPLETED time.
	Completed bool
	// CompletedAt is COMPLETED in UTC; zero when absent.
	CompletedAt time.Time
	// SortOrder is X-APPLE-SORT-ORDER, or "".
	SortOrder string
}

Todo is a VTODO's index (docs/design/pim.md, Tasks).

func ParseTodo

func ParseTodo(raw []byte, opts Options) (Todo, error)

ParseTodo reads the first VTODO of the first VCALENDAR.

type TodoChange

type TodoChange struct {
	Summary     *string
	Description *string // "" removes DESCRIPTION
	Due         *string // YYYY-MM-DD, or "" to remove DUE
	Completed   *bool
}

TodoChange is a change to a task; nil fields keep their values.

Jump to

Keyboard shortcuts

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