fix(caldav): properly parse durations when returning VTODOs

Resolves https://github.com/go-vikunja/frontend/issues/55
This commit is contained in:
kolaente 2022-07-07 23:20:37 +02:00
parent f5a4c136fb
commit 2b074c60a7
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B

View file

@ -17,7 +17,6 @@
package caldav
import (
"fmt"
"regexp"
"strconv"
"strings"
@ -150,6 +149,15 @@ END:VCALENDAR` // Need a line break
return
}
func formatDuration(duration time.Duration) string {
seconds := duration.Seconds() - duration.Minutes()*60
minutes := duration.Minutes() - duration.Hours()*60
return strconv.FormatFloat(duration.Hours(), 'f', 0, 64) + `H` +
strconv.FormatFloat(minutes, 'f', 0, 64) + `M` +
strconv.FormatFloat(seconds, 'f', 0, 64) + `S`
}
// ParseTodos returns a caldav vcalendar string with todos
func ParseTodos(config *Config, todos []*Todo) (caldavtodos string) {
caldavtodos = `BEGIN:VCALENDAR
@ -211,7 +219,7 @@ CREATED:` + makeCalDavTimeFromTimeStamp(t.Created)
if t.Duration != 0 {
caldavtodos += `
DURATION:PT` + fmt.Sprintf("%.6f", t.Duration.Hours()) + `H` + fmt.Sprintf("%.6f", t.Duration.Minutes()) + `M` + fmt.Sprintf("%.6f", t.Duration.Seconds()) + `S`
DURATION:PT` + formatDuration(t.Duration)
}
if t.Priority != 0 {