diff --git a/src/calanonsync/caldav.go b/src/calanonsync/caldav.go index 5253384..d9364ca 100644 --- a/src/calanonsync/caldav.go +++ b/src/calanonsync/caldav.go @@ -2,6 +2,7 @@ package main import ( "bufio" + "bytes" "encoding/xml" "errors" "fmt" @@ -135,6 +136,35 @@ func ParseICal(r io.Reader) (*ICal, error) { }, err } +func CreateICal(uid, summary string, start, end time.Time) *ICal { + model := struct { + UID string + Summary string + Start string + End string + Now string + }{ + UID: uid, + Summary: summary, + Start: start.UTC().Format(ICAL_TIME), + End: end.UTC().Format(ICAL_TIME), + Now: time.Now().UTC().Format(ICAL_TIME), + } + + b := &bytes.Buffer{} + err := icalTemplate.Execute(b, model) + if err != nil { + // Internal stuff, so this really should not fail. + panic(err) + } + ical, err := ParseICal(b) + if err != nil { + // Internal stuff, so this really should not fail. + panic(err) + } + return ical +} + func NewCalDAV(settings ServerSettings) *CalDAV { return &CalDAV{ httpClient: http.DefaultClient, @@ -238,7 +268,7 @@ type PropFindResponse struct { } var icalTemplate = template.Must(template.New("icalTemplate").Parse(`BEGIN:VCALENDAR -PRODID:-//aksdb/calanonsync//EN +PRODID:-//aksdb//calanonsync//EN VERSION:2.0 BEGIN:VEVENT UID:{{ .UID }}