fix:#65 added new UID generation for ical File

This commit is contained in:
masterelmar
2023-11-29 11:23:43 +01:00
parent fe4ba9e529
commit f1d178049e
3 changed files with 39 additions and 6 deletions

View File

@@ -4,7 +4,6 @@ import (
"htwkalender/model"
"htwkalender/service/functions"
"htwkalender/service/names"
"strconv"
"time"
"github.com/jordic/goics"
@@ -32,16 +31,18 @@ func (icalModel IcalModel) EmitICal() goics.Componenter {
//add v time zone
icalModel.vtimezone(c)
var timeStamp = time.Now().Local().In(europeTime).Format("20060102T150405")
for i, event := range icalModel.Events {
for _, event := range icalModel.Events {
mapEntry, mappingFound := icalModel.Mapping[event.UUID]
s := goics.NewComponent()
s.SetType("VEVENT")
s.AddProperty(goics.FormatDateTime("DTSTAMP", time.Now().Local().In(europeTime)))
s.AddProperty("UID", strconv.FormatInt(int64(i), 16)+"-"+timeStamp+"@htwkalender.de")
// create a unique id for the event by hashing the event start, end, course and name
var eventHash = functions.HashString(event.Start.String() + event.End.String() + event.Course + event.Name)
s.AddProperty("UID", eventHash+"@htwkalender.de")
s.AddProperty(goics.FormatDateTime("DTEND", event.End.Time().Local().In(europeTime)))
s.AddProperty(goics.FormatDateTime("DTSTART", event.Start.Time().Local().In(europeTime)))