mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender.git
synced 2025-08-02 17:59:14 +02:00
47 lines
928 B
Go
47 lines
928 B
Go
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
|
||
}
|