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
Signed by untrusted user: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 12 additions and 4 deletions

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
@ -172,11 +180,11 @@ SUMMARY:` + t.Summary + getCaldavColor(t.Color)
if t.Start.Unix() > 0 {
caldavtodos += `
DTSTART: ` + makeCalDavTimeFromTimeStamp(t.Start)
DTSTART:` + makeCalDavTimeFromTimeStamp(t.Start)
}
if t.End.Unix() > 0 {
caldavtodos += `
DTEND: ` + makeCalDavTimeFromTimeStamp(t.End)
DTEND:` + makeCalDavTimeFromTimeStamp(t.End)
}
if t.Description != "" {
re := regexp.MustCompile(`\r?\n`)
@ -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 {