fix(caldav): properly parse durations when returning VTODOs
Resolves https://github.com/go-vikunja/frontend/issues/55
This commit is contained in:
parent
f5a4c136fb
commit
2b074c60a7
1 changed files with 12 additions and 4 deletions
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue