mirror of
https://github.com/go-vikunja/vikunja.git
synced 2026-07-16 06:42:23 -05:00
fix(caldav): compute VTODO DURATION components correctly (#3155)
This commit is contained in:
@@ -119,12 +119,14 @@ COLOR:` + color
|
||||
}
|
||||
|
||||
func formatDuration(duration time.Duration) string {
|
||||
seconds := duration.Seconds() - duration.Minutes()*60
|
||||
minutes := duration.Minutes() - duration.Hours()*60
|
||||
seconds := int64(duration.Seconds())
|
||||
hours := seconds / 3600
|
||||
minutes := (seconds % 3600) / 60
|
||||
seconds %= 60
|
||||
|
||||
return strconv.FormatFloat(duration.Hours(), 'f', 0, 64) + `H` +
|
||||
strconv.FormatFloat(minutes, 'f', 0, 64) + `M` +
|
||||
strconv.FormatFloat(seconds, 'f', 0, 64) + `S`
|
||||
return strconv.FormatInt(hours, 10) + `H` +
|
||||
strconv.FormatInt(minutes, 10) + `M` +
|
||||
strconv.FormatInt(seconds, 10) + `S`
|
||||
}
|
||||
|
||||
func getRruleFromInterval(interval int64) (freq string, newInterval int64) {
|
||||
|
||||
@@ -526,6 +526,26 @@ func TestGetCaldavColor(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func Test_formatDuration(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
in time.Duration
|
||||
want string
|
||||
}{
|
||||
{"whole hours", time.Hour, "1H0M0S"},
|
||||
{"hours and minutes", time.Hour + 30*time.Minute, "1H30M0S"},
|
||||
{"minutes only", 30 * time.Minute, "0H30M0S"},
|
||||
{"minutes only, not a round hour", 45 * time.Minute, "0H45M0S"},
|
||||
{"hours, minutes and seconds", 2*time.Hour + 15*time.Minute + 30*time.Second, "2H15M30S"},
|
||||
{"seconds only", 30 * time.Second, "0H0M30S"},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
assert.Equal(t, tt.want, formatDuration(tt.in))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestEscapeICalText(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
||||
Reference in New Issue
Block a user