ical

package
v1.1.10 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 17 Imported by: 2 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 ical defines an iCalendar, a calendar of events and tasks, which is encoded and decoded as iCalendar 2.0, and its images, which can be embedded in it, as artwork. Reference: https://www.rfc-editor.org/rfc/rfc5545

Index

Constants

View Source
const (
	// ContentType is the content type of an iCalendar
	ContentType = "text/calendar"

	// TaskType and EventType are the content types of an iCalendar whose
	// components are all tasks, VTODO, or all events, VEVENT, with the
	// component parameter of RFC 5545, so a client can tell them apart
	// without reading them
	TaskType  = ContentType + "; component=VTODO"
	EventType = ContentType + "; component=VEVENT"
)
View Source
const (
	// DefaultProdID is the product which writes a calendar without one
	DefaultProdID = "-//mutablelogic//go-metadata//EN"
)
View Source
const (
	// MaxLineSize is the longest line which is read, once it's unfolded,
	// which includes an image of several megabytes, as base64
	MaxLineSize = 16 << 20
)

Variables

This section is empty.

Functions

func Location

func Location(tzid string) (*time.Location, bool)

Location returns the zone of a TZID: a zone in the database, such as Europe/Berlin, or an offset, such as +02:00, which some calendars use, as a zone of that name, or false when it's neither

Types

type Calendar

type Calendar struct {
	ProdID      string   `json:"prodid,omitempty"`      // The product which wrote it
	Name        string   `json:"name,omitempty"`        // Its name, such as Birthdays
	Description string   `json:"description,omitempty"` // Its description
	TZ          string   `json:"tz,omitempty"`          // Its zone, such as Europe/Berlin
	Image       *Image   `json:"image,omitempty"`       // Its image, embedded or linked
	Events      []*Event `json:"events,omitempty"`      // Its events and tasks
	// contains filtered or unexported fields
}

Calendar is a calendar of events and tasks

func Decode

func Decode(r io.Reader) (*Calendar, error)

Decode returns the calendar of r, which is iCalendar 2.0, with its events and tasks, without its other components, such as alarms and zones, or an empty calendar when there's none. An event without a start, or a task without a start or when it's due, isn't returned. When a calendar has more than one VCALENDAR, they're one calendar.

func (*Calendar) Components added in v1.1.9

func (c *Calendar) Components() (events, tasks int)

Components returns how many events and tasks the calendar has: those of its Events, as they are now, and those it was decoded of which aren't in Events, such as an event without a start

func (*Calendar) ContentType added in v1.1.5

func (c *Calendar) ContentType() string

ContentType returns the content type of the calendar: TaskType when its components are all tasks, EventType when they're all events, or else ContentType, when they're both, or it has none (see Components)

func (*Calendar) MarshalText

func (c *Calendar) MarshalText() ([]byte, error)

MarshalText returns the calendar as iCalendar 2.0 (see Encoder.Encode)

func (*Calendar) UnmarshalText

func (c *Calendar) UnmarshalText(data []byte) error

UnmarshalText sets the calendar from iCalendar 2.0 (see Decode)

type Encoder

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

Encoder writes calendars as iCalendar 2.0

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

NewEncoder returns an encoder of calendars to w

func (*Encoder) Encode

func (e *Encoder) Encode(c *Calendar) error

Encode writes the calendar as iCalendar 2.0, with its name and description as Apple's and Google's X-WR-CALNAME and X-WR-CALDESC, which calendars read, and its events and tasks. An event's stamp, which it must have, is the Unix epoch when it isn't set, so a calendar is the same each time it's written. A time in a zone is written with its TZID, without the zone's definition, which calendars which know the zone don't need. Values which are empty aren't written.

type Event

type Event struct {
	Kind         Kind         `json:"kind"`                   // event or task
	UID          string       `json:"uid,omitempty"`          // Its unique identifier
	Summary      string       `json:"summary,omitempty"`      // Its title
	Description  string       `json:"description,omitempty"`  // Its description
	Location     string       `json:"location,omitempty"`     // Where it is
	Geo          *geo.LatLong `json:"geo,omitempty"`          // The position of where it is
	URL          string       `json:"url,omitempty"`          // A link about it
	Start        Time         `json:"start,omitzero"`         // When it starts
	End          Time         `json:"end,omitzero"`           // When it ends, which is exclusive
	Due          Time         `json:"due,omitzero"`           // When a task is due
	Completed    time.Time    `json:"completed,omitzero"`     // When a task was completed
	Parent       string       `json:"parent,omitempty"`       // The UID of a task's parent, of which it's a subtask
	RRule        string       `json:"rrule,omitempty"`        // How it repeats, such as FREQ=YEARLY
	ExDates      []Time       `json:"exdates,omitempty"`      // The starts of a repeating event which it excludes
	RecurrenceID Time         `json:"recurrence_id,omitzero"` // The start of an occurrence it changes
	Status       string       `json:"status,omitempty"`       // Such as CONFIRMED or CANCELLED
	Organizer    string       `json:"organizer,omitempty"`    // The email address of its organizer
	Attendees    []string     `json:"attendees,omitempty"`    // The email addresses of its attendees
	Categories   []string     `json:"categories,omitempty"`   // Its categories, such as Birthdays
	Transparent  bool         `json:"transparent,omitempty"`  // Whether it doesn't make its time busy
	Image        *Image       `json:"image,omitempty"`        // Its image, embedded or linked
	OmitYear     int          `json:"omit_year,omitempty"`    // The year of a start whose year isn't known, such as 1604 for a birthday
	Stamp        time.Time    `json:"stamp,omitzero"`         // When it was written
	Created      time.Time    `json:"created,omitzero"`       // When it was created
	Modified     time.Time    `json:"last_modified,omitzero"` // When it was last changed
}

Event is an event, or a task, of a calendar

type Image

type Image struct {
	MediaType string `json:"media_type,omitempty"`
	Data      []byte `json:"data,omitempty"`
	URI       string `json:"uri,omitempty"`
	Display   string `json:"display,omitempty"`
}

Image is the image of a calendar or an event, which is embedded, as its data and its media type, such as image/png, or linked, as a URI, with how it's displayed, such as BADGE or GRAPHIC Reference: https://www.rfc-editor.org/rfc/rfc7986#section-5.10

func (*Image) Decode

func (i *Image) Decode() image.Image

Decode returns the image, when it's embedded, decoded, or nil when it's a link, or can't be decoded

type Kind

type Kind string

Kind is the kind of an event: an event, or a task

const (
	KindEvent Kind = "event" // A VEVENT
	KindTask  Kind = "task"  // A VTODO
)

type Time

type Time struct {
	Time     time.Time `json:"time"`
	Date     bool      `json:"date,omitempty"`     // A date, without a time
	TZID     string    `json:"tzid,omitempty"`     // The zone of a time
	Floating bool      `json:"floating,omitempty"` // A time without a zone, or in one which isn't known
}

Time is a date, or a time, which is in UTC, in a zone, by its TZID, such as Europe/Berlin, or floating, which is the same time in every zone, as is a time in a zone which isn't known, such as a Windows zone

func Date

func Date(year int, month time.Month, day int) Time

Date returns a date, without a time

func In

func In(t time.Time, location *time.Location) Time

In returns a time in a zone, which is written with its TZID, such as Europe/Berlin

func UTC

func UTC(t time.Time) Time

UTC returns a time in UTC

func (Time) IsZero

func (t Time) IsZero() bool

IsZero returns true when there's no time

Jump to

Keyboard shortcuts

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