ical

package module
v0.0.0-...-fc1c9d8 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2024 License: MIT Imports: 11 Imported by: 58

README

go-ical

GoDoc builds.sr.ht status

An iCalendar library for Go.

License

MIT

Documentation

Overview

Package ical implements the iCalendar file format.

iCalendar is defined in RFC 5545.

Index

Examples

Constants

View Source
const (
	CompCalendar = "VCALENDAR"
	CompEvent    = "VEVENT"
	CompToDo     = "VTODO"
	CompJournal  = "VJOURNAL"
	CompFreeBusy = "VFREEBUSY"
	CompTimezone = "VTIMEZONE"
	CompAlarm    = "VALARM"
)

Components as defined in RFC 5545 section 3.6.

View Source
const (
	CompTimezoneStandard = "STANDARD"
	CompTimezoneDaylight = "DAYLIGHT"
)

Timezone components.

View Source
const (
	// Calendar properties
	PropCalendarScale   = "CALSCALE"
	PropMethod          = "METHOD"
	PropProductID       = "PRODID"
	PropVersion         = "VERSION"
	PropName            = "NAME"
	PropRefreshInterval = "REFRESH-INTERVAL"
	PropSource          = "SOURCE"

	// Component properties
	PropAttach          = "ATTACH"
	PropCategories      = "CATEGORIES"
	PropClass           = "CLASS"
	PropComment         = "COMMENT"
	PropDescription     = "DESCRIPTION"
	PropGeo             = "GEO"
	PropLocation        = "LOCATION"
	PropPercentComplete = "PERCENT-COMPLETE"
	PropPriority        = "PRIORITY"
	PropResources       = "RESOURCES"
	PropStatus          = "STATUS"
	PropSummary         = "SUMMARY"
	PropColor           = "COLOR"
	PropImage           = "IMAGE"

	// Date and time component properties
	PropCompleted     = "COMPLETED"
	PropDateTimeEnd   = "DTEND"
	PropDue           = "DUE"
	PropDateTimeStart = "DTSTART"
	PropDuration      = "DURATION"
	PropFreeBusy      = "FREEBUSY"
	PropTransparency  = "TRANSP"

	// Timezone component properties
	PropTimezoneID         = "TZID"
	PropTimezoneName       = "TZNAME"
	PropTimezoneOffsetFrom = "TZOFFSETFROM"
	PropTimezoneOffsetTo   = "TZOFFSETTO"
	PropTimezoneURL        = "TZURL"

	// Relationship component properties
	PropAttendee     = "ATTENDEE"
	PropContact      = "CONTACT"
	PropOrganizer    = "ORGANIZER"
	PropRecurrenceID = "RECURRENCE-ID"
	PropRelatedTo    = "RELATED-TO"
	PropURL          = "URL"
	PropUID          = "UID"
	PropConference   = "CONFERENCE"

	// Recurrence component properties
	PropExceptionDates  = "EXDATE"
	PropRecurrenceDates = "RDATE"
	PropRecurrenceRule  = "RRULE"

	// Alarm component properties
	PropAction  = "ACTION"
	PropRepeat  = "REPEAT"
	PropTrigger = "TRIGGER"

	// Change management component properties
	PropCreated       = "CREATED"
	PropDateTimeStamp = "DTSTAMP"
	PropLastModified  = "LAST-MODIFIED"
	PropSequence      = "SEQUENCE"

	// Miscellaneous component properties
	PropRequestStatus = "REQUEST-STATUS"
)

Properties as defined in RFC 5545 section 3.7, RFC 5545 section 3.8 and RFC 7986 section 5.

View Source
const (
	ParamAltRep              = "ALTREP"
	ParamCommonName          = "CN"
	ParamCalendarUserType    = "CUTYPE"
	ParamDelegatedFrom       = "DELEGATED-FROM"
	ParamDelegatedTo         = "DELEGATED-TO"
	ParamDir                 = "DIR"
	ParamEncoding            = "ENCODING"
	ParamFormatType          = "FMTTYPE"
	ParamFreeBusyType        = "FBTYPE"
	ParamLanguage            = "LANGUAGE"
	ParamMember              = "MEMBER"
	ParamParticipationStatus = "PARTSTAT"
	ParamRange               = "RANGE"
	ParamRelated             = "RELATED"
	ParamRelationshipType    = "RELTYPE"
	ParamRole                = "ROLE"
	ParamRSVP                = "RSVP"
	ParamSentBy              = "SENT-BY"
	ParamTimezoneID          = "TZID"
	ParamValue               = "VALUE"
	ParamDisplay             = "DISPLAY"
	ParamEmail               = "EMAIL"
	ParamFeature             = "FEATURE"
	ParamLabel               = "LABEL"
)

Property parameters as defined in RFC 5545 section 3.2 and RFC 7986 section 6.

View Source
const (
	MIMEType  = "text/calendar"
	Extension = "ics"
)

MIME type and file extension for iCal, defined in RFC 5545 section 8.1.

Variables

This section is empty.

Functions

This section is empty.

Types

type Calendar

type Calendar struct {
	*Component
}

Calendar is the top-level iCalendar object.

func NewCalendar

func NewCalendar() *Calendar

NewCalendar creates a new calendar object.

func (*Calendar) Events

func (cal *Calendar) Events() []Event

Events extracts the list of events contained in the calendar.

type Component

type Component struct {
	Name     string
	Props    Props
	Children []*Component
}

Component is an iCalendar component: collections of properties that express a particular calendar semantic. A components can be an events, a to-do, a journal entry, timezone information, free/busy time information, or an alarm.

func NewComponent

func NewComponent(name string) *Component

NewComponent creates a new component with the specified name.

func (*Component) RecurrenceSet

func (comp *Component) RecurrenceSet(loc *time.Location) (*rrule.Set, error)

RecurrenceSet returns the Recurrence Set for this component.

type ConferenceFeature

type ConferenceFeature string

ConferenceFeature describes features of a conference. Defined in RFC 7986 section 5.7.

const (
	ConferenceAudio     ConferenceFeature = "AUDIO"
	ConferenceChat      ConferenceFeature = "CHAT"
	ConferenceFeed      ConferenceFeature = "FEED"
	ConferenceModerator ConferenceFeature = "MODERATOR"
	ConferencePhone     ConferenceFeature = "PHONE"
	ConferenceScreen    ConferenceFeature = "SCREEN"
	ConferenceVideo     ConferenceFeature = "VIDEO"
)

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}
Example
// Let's assume r is an io.Reader containing iCal data
var r io.Reader

dec := ical.NewDecoder(r)
for {
	cal, err := dec.Decode()
	if err == io.EOF {
		break
	} else if err != nil {
		log.Fatal(err)
	}

	for _, event := range cal.Events() {
		summary, err := event.Props.Text(ical.PropSummary)
		if err != nil {
			log.Fatal(err)
		}
		log.Printf("Found event: %v", summary)
	}
}
Output:

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

func (*Decoder) Decode

func (dec *Decoder) Decode() (*Calendar, error)

type Encoder

type Encoder struct {
	// contains filtered or unexported fields
}
Example
event := ical.NewEvent()
event.Props.SetText(ical.PropUID, "uid@example.org")
event.Props.SetDateTime(ical.PropDateTimeStamp, time.Now())
event.Props.SetText(ical.PropSummary, "My awesome event")
event.Props.SetDateTime(ical.PropDateTimeStart, time.Now().Add(24*time.Hour))

cal := ical.NewCalendar()
cal.Props.SetText(ical.PropVersion, "2.0")
cal.Props.SetText(ical.PropProductID, "-//xyz Corp//NONSGML PDA Calendar Version 1.0//EN")
cal.Children = append(cal.Children, event.Component)

var buf bytes.Buffer
if err := ical.NewEncoder(&buf).Encode(cal); err != nil {
	log.Fatal(err)
}

log.Print(buf.String())
Output:

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

func (*Encoder) Encode

func (enc *Encoder) Encode(cal *Calendar) error

type Event

type Event struct {
	*Component
}

Event represents a scheduled amount of time on a calendar.

func NewEvent

func NewEvent() *Event

NewEvent creates a new event.

func (*Event) DateTimeEnd

func (e *Event) DateTimeEnd(loc *time.Location) (time.Time, error)

DateTimeEnd returns the non-inclusive end of the event.

func (*Event) DateTimeStart

func (e *Event) DateTimeStart(loc *time.Location) (time.Time, error)

DateTimeStart returns the inclusive start of the event.

func (*Event) SetStatus

func (e *Event) SetStatus(status EventStatus)

func (*Event) Status

func (e *Event) Status() (EventStatus, error)

type EventStatus

type EventStatus string
const (
	EventTentative EventStatus = "TENTATIVE"
	EventConfirmed EventStatus = "CONFIRMED"
	EventCancelled EventStatus = "CANCELLED"
)

type ImageDisplay

type ImageDisplay string

ImageDisplay describes the way an image for a component can be displayed. Defined in RFC 7986 section 6.1.

const (
	ImageBadge     ImageDisplay = "BADGE"
	ImageGraphic   ImageDisplay = "GRAPHIC"
	ImageFullSize  ImageDisplay = "FULLSIZE"
	ImageThumbnail ImageDisplay = "THUMBNAIL"
)

type Params

type Params map[string][]string

Params is a set of property parameters.

func (Params) Add

func (params Params) Add(name, value string)

func (Params) Del

func (params Params) Del(name string)

func (Params) Get

func (params Params) Get(name string) string

func (Params) Set

func (params Params) Set(name, value string)

func (Params) Values

func (params Params) Values(name string) []string

type Prop

type Prop struct {
	Name   string
	Params Params
	Value  string
}

Prop is a component property.

func NewProp

func NewProp(name string) *Prop

NewProp creates a new property with the specified name.

func (*Prop) Binary

func (prop *Prop) Binary() ([]byte, error)

func (*Prop) Bool

func (prop *Prop) Bool() (bool, error)

func (*Prop) DateTime

func (prop *Prop) DateTime(loc *time.Location) (time.Time, error)

DateTime parses the property value as a date-time or a date.

func (*Prop) Duration

func (prop *Prop) Duration() (time.Duration, error)

func (*Prop) Float

func (prop *Prop) Float() (float64, error)

func (*Prop) Int

func (prop *Prop) Int() (int, error)

func (*Prop) SetBinary

func (prop *Prop) SetBinary(b []byte)

func (*Prop) SetDate

func (prop *Prop) SetDate(t time.Time)

func (*Prop) SetDateTime

func (prop *Prop) SetDateTime(t time.Time)

func (*Prop) SetDuration

func (prop *Prop) SetDuration(dur time.Duration)

func (*Prop) SetText

func (prop *Prop) SetText(text string)

func (*Prop) SetTextList

func (prop *Prop) SetTextList(l []string)

func (*Prop) SetURI

func (prop *Prop) SetURI(u *url.URL)

func (*Prop) SetValueType

func (prop *Prop) SetValueType(t ValueType)

func (*Prop) Text

func (prop *Prop) Text() (string, error)

func (*Prop) TextList

func (prop *Prop) TextList() ([]string, error)

func (*Prop) URI

func (prop *Prop) URI() (*url.URL, error)

URI parses the property value as a URI or binary. If the value is binary, a data URI is returned.

func (*Prop) ValueType

func (prop *Prop) ValueType() ValueType

type Props

type Props map[string][]Prop

Props is a set of component properties.

func (Props) Add

func (props Props) Add(prop *Prop)

func (Props) DateTime

func (props Props) DateTime(name string, loc *time.Location) (time.Time, error)

func (Props) Del

func (props Props) Del(name string)

func (Props) Get

func (props Props) Get(name string) *Prop

func (Props) RecurrenceRule

func (props Props) RecurrenceRule() (*rrule.ROption, error)

Returns an ROption based on the events RRULE.

This object can then be used to construct `RRule` instances for different fields, for example, an rrule based on `DTSTART`:

roption, err := props.RecurrenceRule()
if err != nil {
	log.Fatalf("error parsing rrule:", err)
}
if roption == nil {
	log.Fatalf("props have no RRULE")
}

dtstart, err := props.DateTime("DTSTART", nil)
if err != nil {
	log.Fatalf("error parsing dtstart:", err)
}
roption.Dtstart = dtstart

return rrule.NewRRule(*roption)

This object can then be used to calculate the `DTSTART` of all recurrances.

func (Props) Set

func (props Props) Set(prop *Prop)

func (Props) SetDate

func (props Props) SetDate(name string, t time.Time)

func (Props) SetDateTime

func (props Props) SetDateTime(name string, t time.Time)

func (Props) SetRecurrenceRule

func (props Props) SetRecurrenceRule(rule *rrule.ROption)

func (Props) SetText

func (props Props) SetText(name, text string)

func (Props) SetURI

func (props Props) SetURI(name string, u *url.URL)

func (Props) Text

func (props Props) Text(name string) (string, error)

func (Props) URI

func (props Props) URI(name string) (*url.URL, error)

func (Props) Values

func (props Props) Values(name string) []Prop

type ValueType

type ValueType string

ValueType is the type of a property.

const (
	ValueDefault         ValueType = ""
	ValueBinary          ValueType = "BINARY"
	ValueBool            ValueType = "BOOLEAN"
	ValueCalendarAddress ValueType = "CAL-ADDRESS"
	ValueDate            ValueType = "DATE"
	ValueDateTime        ValueType = "DATE-TIME"
	ValueDuration        ValueType = "DURATION"
	ValueFloat           ValueType = "FLOAT"
	ValueInt             ValueType = "INTEGER"
	ValuePeriod          ValueType = "PERIOD"
	ValueRecurrence      ValueType = "RECUR"
	ValueText            ValueType = "TEXT"
	ValueTime            ValueType = "TIME"
	ValueURI             ValueType = "URI"
	ValueUTCOffset       ValueType = "UTC-OFFSET"
)

Value types as defined in RFC 5545 section 3.3.

Jump to

Keyboard shortcuts

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