 Documentation
      ¶
      Documentation
      ¶
    
    
  
    
  
    Overview ¶
Package ical2 provides a data model for the iCalendar specification. Marshalling to the textual iCalendar ics format is implemented. Unmarshalling is not currently supported.
See https://tools.ietf.org/html/rfc5545 https://tools.ietf.org/html/rfc6868 https://tools.ietf.org/html/rfc7986.
Availability (https://tools.ietf.org/html/rfc7953) is not supported.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Extension ¶
Extension is a key/value struct for any additional non-standard or unsupported calendar properties.
type VAlarm ¶
type VAlarm interface {
	VComponent
	IsAlarm()
}
    VAlarm is an alarm component.
Example (Audio) ¶
package main
import (
	"fmt"
	"github.com/rickb777/ical2"
	"github.com/rickb777/ical2/parameter"
	"github.com/rickb777/ical2/value"
	"time"
)
func main() {
	const tz = "Europe/Paris"
	zone, _ := time.LoadLocation(tz)
	dt := time.Date(2014, time.Month(1), 1, 7, 0, 0, 0, zone)
	ds := dt.Add(time.Hour)
	de := ds.Add(5 * time.Hour)
	alarm := &ical2.VAudioAlarm{
		Trigger:  value.DateTime(ds.Add(-time.Hour).In(time.UTC)),
		Duration: value.Duration("PT10M"),
		Repeat:   value.Integer(3),
		Attach: value.URI("http://example.com/clips/poke.aud").
			With(parameter.FmtTypeOf("audio", "basic")),
	}
	event := &ical2.VEvent{
		UID:     value.Text("123"),
		DTStamp: value.TStamp(dt),
		Start:   value.DateTime(ds).With(parameter.TZid(tz)),
		End:     value.DateTime(de).With(parameter.TZid(tz)),
		Status:  value.NeedsActionStatus(),
		Alarm:   []ical2.VAlarm{alarm},
	}
	c := ical2.NewVCalendar("-//My App//Event Calendar//EN").With(event)
	// usually you'd Encode to some io.Writer
	//c.Encode(w)
	// but for this example, we'll just stringify
	fmt.Printf(c.String())
}
Output: BEGIN:VCALENDAR VERSION:2.0 PRODID:-//My App//Event Calendar//EN CALSCALE:GREGORIAN BEGIN:VEVENT DTSTART;VALUE=DATE-TIME;TZID=Europe/Paris:20140101T080000 DTEND;VALUE=DATE-TIME;TZID=Europe/Paris:20140101T130000 DTSTAMP:20140101T060000Z UID:123 STATUS:NEEDS-ACTION BEGIN:VALARM ACTION:AUDIO TRIGGER;VALUE=DATE-TIME:20140101T060000Z DURATION;VALUE=DURATION:PT10M REPEAT;VALUE=INTEGER:3 ATTACH;VALUE=URI;FMTTYPE=audio/basic:http://example.com/clips/poke.aud END:VALARM END:VEVENT END:VCALENDAR
Example (Display) ¶
package main
import (
	"fmt"
	"github.com/rickb777/ical2"
	"github.com/rickb777/ical2/value"
	"time"
)
func main() {
	dt := time.Date(2014, time.Month(1), 1, 7, 0, 0, 0, time.UTC)
	ds := dt.Add(time.Hour)
	de := ds.Add(5 * time.Hour)
	alarm := &ical2.VDisplayAlarm{
		Description: value.Text("Wakey wakey"),
		Trigger:     value.Duration("-PT10M"),
	}
	event := &ical2.VEvent{
		UID:     value.Text("123"),
		DTStamp: value.TStamp(dt),
		Start:   value.DateTime(ds),
		End:     value.DateTime(de),
		Alarm:   []ical2.VAlarm{alarm},
	}
	c := ical2.NewVCalendar("-//My App//Event Calendar//EN").With(event)
	// usually you'd Encode to some io.Writer
	//c.Encode(w)
	// but for this example, we'll just stringify
	fmt.Printf(c.String())
}
Output: BEGIN:VCALENDAR VERSION:2.0 PRODID:-//My App//Event Calendar//EN CALSCALE:GREGORIAN BEGIN:VEVENT DTSTART;VALUE=DATE-TIME:20140101T080000Z DTEND;VALUE=DATE-TIME:20140101T130000Z DTSTAMP:20140101T070000Z UID:123 BEGIN:VALARM ACTION:DISPLAY DESCRIPTION:Wakey wakey TRIGGER;VALUE=DURATION:-PT10M END:VALARM END:VEVENT END:VCALENDAR
Example (Email) ¶
package main
import (
	"fmt"
	"github.com/rickb777/ical2"
	"github.com/rickb777/ical2/parameter"
	"github.com/rickb777/ical2/value"
	"time"
)
func main() {
	const tz = "Europe/Paris"
	zone, _ := time.LoadLocation(tz)
	dt := time.Date(2014, time.Month(1), 1, 7, 0, 0, 0, zone)
	ds := dt.Add(time.Hour)
	de := ds.Add(5 * time.Hour)
	alarm := &ical2.VEmailAlarm{
		Description: value.Text("Wakey wakey"),
		Trigger:     value.Duration("-PT10M"),
		Summary:     value.Text("There are things to be done."),
		Attendee:    []value.URIValue{value.CalAddress("john_public@example.com")},
	}
	event := &ical2.VEvent{
		UID:     value.Text("123"),
		DTStamp: value.TStamp(dt),
		Start:   value.DateTime(ds).With(parameter.TZid(tz)),
		End:     value.DateTime(de).With(parameter.TZid(tz)),
		Alarm:   []ical2.VAlarm{alarm},
	}
	c := ical2.NewVCalendar("-//My App//Event Calendar//EN").With(event)
	// usually you'd Encode to some io.Writer
	//c.Encode(w)
	// but for this example, we'll just stringify
	fmt.Printf(c.String())
}
Output: BEGIN:VCALENDAR VERSION:2.0 PRODID:-//My App//Event Calendar//EN CALSCALE:GREGORIAN BEGIN:VEVENT DTSTART;VALUE=DATE-TIME;TZID=Europe/Paris:20140101T080000 DTEND;VALUE=DATE-TIME;TZID=Europe/Paris:20140101T130000 DTSTAMP:20140101T060000Z UID:123 BEGIN:VALARM ACTION:EMAIL DESCRIPTION:Wakey wakey TRIGGER;VALUE=DURATION:-PT10M SUMMARY:There are things to be done. ATTENDEE:mailto:john_public@example.com END:VALARM END:VEVENT END:VCALENDAR
type VAudioAlarm ¶
type VAudioAlarm struct {
	Trigger  value.Trigger // required
	Duration value.DurationValue
	Repeat   value.IntegerValue
	Attach   value.Attachable // optional
}
    VAudioAlarm captures a calendar event
func (*VAudioAlarm) EncodeIcal ¶
func (e *VAudioAlarm) EncodeIcal(b *ics.Buffer, method value.MethodValue) error
EncodeIcal serialises the event to the buffer in iCalendar ics format
type VCalendar ¶
type VCalendar struct {
	// RFC-5545 properties
	Version  value.TextValue   // 2.0
	ProdId   value.TextValue   // -//My Company//NONSGML Event Calendar//EN
	Method   value.MethodValue // PUBLISH, REQUEST,
	CalScale value.TextValue   // GREGORIAN
	// RFC-7986 properties
	Name            value.TextValue // My Calendar Name
	Description     value.TextValue // A description of my calendar
	UID             value.TextValue
	URL             value.TextValue     // http://my.calendar/url
	LastModified    value.DateTimeValue // can also be specified per VComponent
	RecurrenceId    value.DateTimeValue
	RefreshInterval value.DurationValue // PT12H
	Color           value.TextValue     // CSS3 color name
	//X_WR_CALNAME string // My Calendar Name
	//X_WR_CALDESC string // A description of my calendar
	//X_WR_TIMEZONE string // Europe/London
	//X_PUBLISHED_TTL  string // PT12H
	Extensions []Extension
	VComponent []VComponent
}
    VCalendar is a calendar as per RFC-5545 https://tools.ietf.org/html/rfc5545.
func NewVCalendar ¶
NewVCalendar constructs a new VCalendar with the required properties set. The version is set to 2.0 and the calendar scale is Gregorian.
func (*VCalendar) Encode ¶
Encode encodes the calendar in ICS format, writing it to some Writer. The line endings are "\r\n" for normal iCalendar transmission purposes.
func (*VCalendar) EncodePlain ¶
EncodePlain encodes the calendar in ICS format, writing it to some Writer. The line ending are "\n" for non-transmission purposes, e.g. for viewing.
func (*VCalendar) Extend ¶
Extend adds an extension property to the calendar. The VCalendar modified and is returned.
func (*VCalendar) String ¶
String returns the ICS formatted content, albeit using "\n" line endings.
func (*VCalendar) With ¶
func (c *VCalendar) With(component VComponent) *VCalendar
With associates a component with the calendar. The VCalendar modified and is returned.
type VComponent ¶
type VComponent interface {
	EncodeIcal(b *ics.Buffer, method value.MethodValue) error
}
    VComponent is an item that belongs to a calendar.
type VDisplayAlarm ¶
type VDisplayAlarm struct {
	Description value.TextValue // required
	Trigger     value.Trigger   // required
	Duration    value.DurationValue
	Repeat      value.IntegerValue
}
    VDisplayAlarm captures a calendar event
func (*VDisplayAlarm) EncodeIcal ¶
func (e *VDisplayAlarm) EncodeIcal(b *ics.Buffer, method value.MethodValue) error
EncodeIcal serialises the event to the buffer in iCalendar ics format
type VEmailAlarm ¶
type VEmailAlarm struct {
	Description value.TextValue  // required
	Trigger     value.Trigger    // required
	Summary     value.TextValue  // required
	Attendee    []value.URIValue // required one or more
	Duration    value.DurationValue
	Repeat      value.IntegerValue
	Attach      []value.Attachable // optional
}
    VEmailAlarm captures a calendar event
func (*VEmailAlarm) EncodeIcal ¶
func (e *VEmailAlarm) EncodeIcal(b *ics.Buffer, method value.MethodValue) error
EncodeIcal serialises the event to the buffer in iCalendar ics format
type VEvent ¶
type VEvent struct {
	UID            value.TextValue
	DTStamp        value.DateTimeValue
	Start          value.DateTimeValue
	End            value.DateTimeValue
	Created        value.DateTimeValue
	LastModified   value.DateTimeValue
	ExceptionDate  value.DateTimeValue
	RecurrenceDate value.Temporal // DateTime or Period
	RecurrenceRule value.RecurrenceValue
	Organizer      value.URIValue
	Attendee       []value.URIValue
	Conference     []value.URIValue
	Contact        value.TextValue
	Summary        value.TextValue
	Description    value.TextValue
	Class          value.ClassValue // PUBLIC, PRIVATE, CONFIDENTIAL
	Comment        []value.TextValue
	RelatedTo      value.TextValue
	Categories     value.ListValue
	Resources      value.ListValue
	Sequence       value.IntegerValue
	Priority       value.IntegerValue // in the range 0 to 9; 0 is undefined; 1 is highest; 9 is lowest
	Status         value.StatusValue
	Location       value.TextValue
	Geo            value.GeoValue
	Transparency   value.TransparencyValue
	Color          value.TextValue // CSS3 color name
	Attach         []value.Attachable
	Image          []value.Attachable
	Alarm          []VAlarm
}
    VEvent captures a calendar event
Example (Meeting) ¶
package main
import (
	"fmt"
	"github.com/rickb777/ical2"
	"github.com/rickb777/ical2/parameter"
	"github.com/rickb777/ical2/parameter/cuvalue"
	"github.com/rickb777/ical2/parameter/partstat"
	"github.com/rickb777/ical2/parameter/role"
	"github.com/rickb777/ical2/value"
	"time"
)
func main() {
	dt := time.Date(2014, time.Month(1), 1, 8, 0, 0, 0, time.UTC)
	ds := dt.Add(48 * time.Hour)
	de := ds.Add(72 * time.Hour)
	shared := parameter.Parameters{
		cuvalue.CUType(cuvalue.INDIVIDUAL),
		role.Role(role.REQ_PARTICIPANT),
		partstat.PartStat(partstat.NEEDS_ACTION),
		parameter.Rsvp(true),
		parameter.Single("X-NUM-GUESTS", "0"),
	}
	cath1 := value.CalAddress("cath.dragon@example.com").
		With(shared...).
		With(parameter.CommonName("Cath Dragon"))
	ann1 := value.CalAddress("anne.bollin@example.com").
		With(shared...).
		With(parameter.CommonName("Anne Bollin"))
	jane := value.CalAddress("jane.seemoor@example.com").
		With(shared...).
		With(parameter.CommonName("Jane Seemoor"))
	ann2 := value.CalAddress("anne@cleves.com").
		With(shared...).
		With(parameter.CommonName("Anne Cleaver"))
	cath2 := value.CalAddress("cath@thehowards.com").
		With(shared...).
		With(parameter.CommonName("Cath Howard"))
	cath3 := value.CalAddress("catherine.parr@respectable.com").
		With(shared...).
		With(parameter.CommonName("Cath Parr"))
	event := &ical2.VEvent{
		UID:          value.Text("0ibinszut0oiksq0sa0ac98d46@google.com"),
		DTStamp:      value.TStamp(dt),
		Created:      value.TStamp(dt.Add(-2 * time.Hour)),
		LastModified: value.TStamp(dt.Add(-1 * time.Hour)),
		Sequence:     value.Integer(0),
		Status:       value.ConfirmedStatus(),
		Start:        value.TStamp(ds),
		End:          value.TStamp(de),
		Organizer:    value.CalAddress("ht@throne.com").With(parameter.CommonName("H.Tudwr")),
		Attendee:     []value.URIValue{cath1, ann1, jane, ann2, cath2, cath3},
		Summary:      value.Text("Meet the family"),
		Description:  value.Text("This is a great chance to meet each other!"),
		Location:     value.Text("South Bank, London SE1 9PX"),
		Geo:          value.Geo(51.506616, -0.11538874),
		Transparency: value.Opaque(),
		Comment:      []value.TextValue{value.Text("History in the making")},
	}
	c := ical2.NewVCalendar("-//My App//Event Calendar//EN").With(event)
	c.Method = value.Request()
	fmt.Printf(c.String())
}
Output: BEGIN:VCALENDAR VERSION:2.0 PRODID:-//My App//Event Calendar//EN CALSCALE:GREGORIAN METHOD:REQUEST BEGIN:VEVENT DTSTART:20140103T080000Z DTEND:20140106T080000Z DTSTAMP:20140101T080000Z UID:0ibinszut0oiksq0sa0ac98d46@google.com ORGANIZER;CN=H.Tudwr:mailto:ht@throne.com ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP= TRUE;X-NUM-GUESTS=0;CN=Cath Dragon:mailto:cath.dragon@example.com ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP= TRUE;X-NUM-GUESTS=0;CN=Anne Bollin:mailto:anne.bollin@example.com ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP= TRUE;X-NUM-GUESTS=0;CN=Jane Seemoor:mailto:jane.seemoor@example.com ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP= TRUE;X-NUM-GUESTS=0;CN=Anne Cleaver:mailto:anne@cleves.com ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP= TRUE;X-NUM-GUESTS=0;CN=Cath Howard:mailto:cath@thehowards.com ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP= TRUE;X-NUM-GUESTS=0;CN=Cath Parr:mailto:catherine.parr@respectable.com SUMMARY:Meet the family DESCRIPTION:This is a great chance to meet each other! LOCATION:South Bank\, London SE1 9PX GEO;VALUE=FLOAT:51.506616;-0.11538874 COMMENT:History in the making CREATED:20140101T060000Z LAST-MODIFIED:20140101T070000Z SEQUENCE;VALUE=INTEGER:0 STATUS:CONFIRMED TRANSP:OPAQUE END:VEVENT END:VCALENDAR
Example (Recurrence) ¶
package main
import (
	"fmt"
	"github.com/rickb777/ical2"
	"github.com/rickb777/ical2/parameter"
	"github.com/rickb777/ical2/parameter/role"
	"github.com/rickb777/ical2/value"
	"time"
)
func main() {
	dt := time.Date(2014, time.Month(1), 1, 7, 0, 0, 0, time.UTC)
	ds := dt.Add(time.Hour)
	de := ds.Add(5 * time.Hour)
	// Recurrence rule are sophisticated: see recur_test.go for many examples.
	rv := value.Recurrence(value.WEEKLY)
	rv.ByDay = []value.WeekDayNum{value.MO, value.WE, value.FR}
	event := &ical2.VEvent{
		UID:            value.Text("123"),
		DTStamp:        value.TStamp(dt),
		Start:          value.DateTime(ds),
		End:            value.DateTime(de),
		Organizer:      value.CalAddress("ht@throne.com").With(parameter.CommonName("H.Tudwr")),
		Attendee:       []value.URIValue{value.CalAddress("ann.blin@example.com").With(role.Role(role.REQ_PARTICIPANT), parameter.CommonName("Ann Blin"))},
		Summary:        value.Text("Event summary"),
		Description:    value.Text("This describes the event."),
		Transparency:   value.Opaque(),
		RecurrenceRule: rv,
		// can have RecurrenceDate too, in which case the event sets are unioned.
		// Use ExceptionDate to exclude specific dates from the event set.
	}
	c := ical2.NewVCalendar("-//My App//Event Calendar//EN").With(event)
	// usually you'd Encode to some io.Writer
	//c.Encode(w)
	// but for this example, we'll just stringify
	fmt.Printf(c.String())
}
Output: BEGIN:VCALENDAR VERSION:2.0 PRODID:-//My App//Event Calendar//EN CALSCALE:GREGORIAN BEGIN:VEVENT DTSTART;VALUE=DATE-TIME:20140101T080000Z DTEND;VALUE=DATE-TIME:20140101T130000Z DTSTAMP:20140101T070000Z UID:123 ORGANIZER;CN=H.Tudwr:mailto:ht@throne.com ATTENDEE;ROLE=REQ-PARTICIPANT;CN=Ann Blin:mailto:ann.blin@example.com SUMMARY:Event summary DESCRIPTION:This describes the event. RRULE;VALUE=RECUR:FREQ=WEEKLY;BYDAY=MO,WE,FR TRANSP:OPAQUE END:VEVENT END:VCALENDAR
Example (Timezone) ¶
package main
import (
	"fmt"
	"github.com/rickb777/ical2"
	"github.com/rickb777/ical2/parameter"
	"github.com/rickb777/ical2/parameter/display"
	"github.com/rickb777/ical2/parameter/feature"
	"github.com/rickb777/ical2/parameter/role"
	"github.com/rickb777/ical2/value"
	"time"
)
func main() {
	const tz = "Europe/London"
	zone, _ := time.LoadLocation(tz)
	dt := time.Date(2014, time.Month(1), 1, 7, 0, 0, 0, zone)
	ds := dt.Add(time.Hour)
	de := ds.Add(5 * time.Hour)
	event := &ical2.VEvent{
		UID:          value.Text("123"),
		DTStamp:      value.TStamp(dt),
		Start:        value.DateTime(ds).With(parameter.TZid(tz)),
		End:          value.DateTime(de).With(parameter.TZid(tz)),
		Organizer:    value.CalAddress("ht@throne.com").With(parameter.CommonName("H.Tudwr")),
		Attendee:     []value.URIValue{value.CalAddress("ann.blin@example.com").With(role.Role(role.REQ_PARTICIPANT), parameter.CommonName("Ann Blin"))},
		Conference:   []value.URIValue{value.URI("https://chat.example.com/audio?id=123456").With(feature.Feature(feature.AUDIO, feature.VIDEO)).With(parameter.Label("Attendee dial-in"))},
		Contact:      value.Text("T.Moore, Esq."),
		Summary:      value.Text("Event summary"),
		Description:  value.Text("This describes the event."),
		RelatedTo:    value.Text("19960401-080045-4000F192713-0052@example.com"),
		Categories:   value.List("MEETING"),
		Resources:    value.List("CATERING", "CHAIRS"),
		Location:     value.Text("South Bank, London SE1 9PX"),
		Transparency: value.Transparent(),
		Attach: []value.Attachable{value.Binary([]byte("ABC")).
			With(parameter.FmtTypeOf("text", "plain"))},
		Image: []value.Attachable{value.URI("http://example.com/images/party.png").
			With(display.Display(display.BADGE), parameter.FmtTypeOf("image", "png"))},
	}
	c := ical2.NewVCalendar("-//My App//Event Calendar//EN").With(event)
	// usually you'd Encode to some io.Writer
	//c.Encode(w)
	// but for this example, we'll just stringify
	fmt.Printf(c.String())
}
Output: BEGIN:VCALENDAR VERSION:2.0 PRODID:-//My App//Event Calendar//EN CALSCALE:GREGORIAN BEGIN:VEVENT DTSTART;VALUE=DATE-TIME;TZID=Europe/London:20140101T080000 DTEND;VALUE=DATE-TIME;TZID=Europe/London:20140101T130000 DTSTAMP:20140101T070000Z UID:123 ORGANIZER;CN=H.Tudwr:mailto:ht@throne.com ATTENDEE;ROLE=REQ-PARTICIPANT;CN=Ann Blin:mailto:ann.blin@example.com CONFERENCE;VALUE=URI;FEATURE=AUDIO,VIDEO;LABEL=Attendee dial-in:https://cha t.example.com/audio?id=123456 CONTACT:T.Moore\, Esq. SUMMARY:Event summary DESCRIPTION:This describes the event. LOCATION:South Bank\, London SE1 9PX RELATED-TO:19960401-080045-4000F192713-0052@example.com CATEGORIES:MEETING RESOURCES:CATERING,CHAIRS TRANSP:TRANSPARENT ATTACH;VALUE=BINARY;ENCODING=BASE64;FMTTYPE=text/plain:QUJD IMAGE;VALUE=URI;DISPLAY=BADGE;FMTTYPE=image/png:http://example.com/images/p arty.png END:VEVENT END:VCALENDAR
func (*VEvent) AllDay ¶
AllDay changes the start and end to represent dates without time. If they are already configured as dates only, this has no effect.
func (*VEvent) EncodeIcal ¶
EncodeIcal serialises the event to the buffer in iCalendar ics format (a VComponent method).
type VFreeBusy ¶
type VFreeBusy struct {
	UID       value.TextValue
	DTStamp   value.DateTimeValue
	Start     value.DateTimeValue
	End       value.DateTimeValue
	Organizer value.URIValue
	URL       value.URIValue
	Contact   value.TextValue
	Attendee  []value.URIValue
	Comment   []value.TextValue
	FreeBusy  []value.PeriodValue
}
    VFreeBusy captures a calendar event
Example (Publish) ¶
package main
import (
	"fmt"
	"github.com/rickb777/date/timespan"
	"github.com/rickb777/ical2"
	"github.com/rickb777/ical2/parameter/freebusy"
	"github.com/rickb777/ical2/value"
	"time"
)
func main() {
	// This is an example of a "VFREEBUSY" calendar component used to publish busy time information.
	dt := time.Date(1997, time.Month(9), 1, 12, 0, 0, 0, time.UTC)
	ds := time.Date(1998, time.Month(3), 13, 14, 17, 11, 0, time.UTC)
	de := time.Date(1998, time.Month(4), 10, 14, 17, 11, 0, time.UTC)
	t1s := time.Date(1998, time.Month(3), 14, 23, 30, 0, 0, time.UTC)
	t2s := time.Date(1998, time.Month(3), 16, 15, 30, 0, 0, time.UTC)
	t3s := time.Date(1998, time.Month(3), 18, 3, 0, 0, 0, time.UTC)
	event := &ical2.VFreeBusy{
		UID:       value.Text("19970901T115957Z-76A912@example.com"),
		DTStamp:   value.TStamp(dt),
		Start:     value.DateTime(ds),
		End:       value.DateTime(de),
		Organizer: value.CalAddress("jsmith@example.com"),
		URL:       value.URI("http://www.example.com/calendar/busytime/jsmith.ifb"),
		FreeBusy: []value.PeriodValue{
			value.Period(timespan.TimeSpanOf(t1s, time.Hour)).With(freebusy.FbType(freebusy.BUSY)),
			value.Period(timespan.TimeSpanOf(t2s, time.Hour)).With(freebusy.FbType(freebusy.BUSY_TENTATIVE)),
			value.Period(timespan.TimeSpanOf(t3s, time.Hour)).With(freebusy.FbType(freebusy.BUSY_UNAVAILABLE)),
		},
		Comment: []value.TextValue{value.Text("Busy time")},
	}
	c := ical2.NewVCalendar("-//My App//Event Calendar//EN").With(event)
	c.Method = value.Publish()
	// usually you'd Encode to some io.Writer
	//c.Encode(w)
	// but for this example, we'll just stringify
	fmt.Printf(c.String())
}
Output: BEGIN:VCALENDAR VERSION:2.0 PRODID:-//My App//Event Calendar//EN CALSCALE:GREGORIAN METHOD:PUBLISH BEGIN:VFREEBUSY DTSTART;VALUE=DATE-TIME:19980313T141711Z DTEND;VALUE=DATE-TIME:19980410T141711Z DTSTAMP:19970901T120000Z UID:19970901T115957Z-76A912@example.com ORGANIZER:mailto:jsmith@example.com URL;VALUE=URI:http://www.example.com/calendar/busytime/jsmith.ifb COMMENT:Busy time FREEBUSY;VALUE=PERIOD;FBTYPE=BUSY:19980314T233000Z/PT1H FREEBUSY;VALUE=PERIOD;FBTYPE=BUSY-TENTATIVE:19980316T153000Z/PT1H FREEBUSY;VALUE=PERIOD;FBTYPE=BUSY-UNAVAILABLE:19980318T030000Z/PT1H END:VFREEBUSY END:VCALENDAR
Example (Request) ¶
package main
import (
	"fmt"
	"github.com/rickb777/ical2"
	"github.com/rickb777/ical2/value"
	"time"
)
func main() {
	// This is an example of a "VFREEBUSY" calendar component used to request free or busy time information
	dt := time.Date(1997, time.Month(9), 1, 8, 30, 0, 0, time.UTC)
	ds := time.Date(1997, time.Month(10), 15, 5, 0, 0, 0, time.UTC)
	de := time.Date(1997, time.Month(10), 16, 5, 0, 0, 0, time.UTC)
	event := &ical2.VFreeBusy{
		UID:       value.Text("19970901T082949Z-FA43EF@example.com"),
		DTStamp:   value.TStamp(dt),
		Start:     value.DateTime(ds),
		End:       value.DateTime(de),
		Organizer: value.CalAddress("jane_doe@example.com"),
		Attendee:  []value.URIValue{value.CalAddress("john_public@example.com")},
	}
	c := ical2.NewVCalendar("-//My App//Event Calendar//EN").With(event)
	c.Method = value.Request()
	// usually you'd Encode to some io.Writer
	//c.Encode(w)
	// but for this example, we'll just stringify
	fmt.Printf(c.String())
}
Output: BEGIN:VCALENDAR VERSION:2.0 PRODID:-//My App//Event Calendar//EN CALSCALE:GREGORIAN METHOD:REQUEST BEGIN:VFREEBUSY DTSTART;VALUE=DATE-TIME:19971015T050000Z DTEND;VALUE=DATE-TIME:19971016T050000Z DTSTAMP:19970901T083000Z UID:19970901T082949Z-FA43EF@example.com ORGANIZER:mailto:jane_doe@example.com ATTENDEE:mailto:john_public@example.com END:VFREEBUSY END:VCALENDAR
func (*VFreeBusy) EncodeIcal ¶
EncodeIcal serialises the event to the buffer in iCalendar ics format (a VComponent method).
       Directories
      ¶
      Directories
      ¶
    
    | Path | Synopsis | 
|---|---|
| Package ics provides low-level I/O support for the ical2 api. | Package ics provides low-level I/O support for the ical2 api. | 
| Package parameter handles iCalendar parameters. | Package parameter handles iCalendar parameters. | 
| 
          
            cuvalue
            
            
          
           Package cuvalue enumerates values for calendar user types. | Package cuvalue enumerates values for calendar user types. | 
| 
          
            display
            
            
          
           Package display enumerates values for the display parameter. | Package display enumerates values for the display parameter. | 
| 
          
            feature
            
            
          
           Package feature enumerates values for the feature parameter. | Package feature enumerates values for the feature parameter. | 
| 
          
            freebusy
            
            
          
           Package freebusy enumerates values for the free-busy parameter. | Package freebusy enumerates values for the free-busy parameter. | 
| 
          
            partstat
            
            
          
           Package partstat enumerates values for the participation status parameter. | Package partstat enumerates values for the participation status parameter. | 
| 
          
            role
            
            
          
           Package role enumerates values for the participation role parameter. | Package role enumerates values for the participation role parameter. | 
| 
          
            valuetype
            
            
          
           Package valuetype enumerates values of the type options for parameters (the VALUE parameter). | Package valuetype enumerates values of the type options for parameters (the VALUE parameter). |