mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender.git
synced 2025-08-03 10:19:14 +02:00
well formatted iCalendar like RFC5545
This commit is contained in:
46
backend/service/ical/icsComponenter.go
Normal file
46
backend/service/ical/icsComponenter.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package ical
|
||||
|
||||
import (
|
||||
"github.com/jordic/goics"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type HtwkalenderComponent struct {
|
||||
*goics.Component
|
||||
}
|
||||
|
||||
func NewHtwkalenderComponent() *HtwkalenderComponent {
|
||||
return &HtwkalenderComponent{
|
||||
Component: goics.NewComponent(),
|
||||
}
|
||||
}
|
||||
|
||||
// Writes the component to the Writer
|
||||
func (c *HtwkalenderComponent) Write(w *goics.ICalEncode) {
|
||||
w.WriteLine("BEGIN:" + c.Tipo + goics.CRLF)
|
||||
|
||||
// Iterate over component properties
|
||||
var keys []string
|
||||
for k := range c.Properties {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
for _, key := range keys {
|
||||
vals := c.Properties[key]
|
||||
for _, val := range vals {
|
||||
w.WriteLine(WriteStringField(key, val))
|
||||
}
|
||||
}
|
||||
|
||||
for _, xc := range c.Elements {
|
||||
xc.Write(w)
|
||||
}
|
||||
|
||||
w.WriteLine("END:" + c.Tipo + goics.CRLF)
|
||||
}
|
||||
|
||||
// WriteStringField UID:asdfasdfаs@dfasdf.com
|
||||
func WriteStringField(key string, val string) string {
|
||||
return strings.ToUpper(key) + ":" + (val) + goics.CRLF
|
||||
}
|
Reference in New Issue
Block a user