fix(caldav): use const for repeat modes

This commit is contained in:
kolaente 2022-12-24 14:34:59 +01:00
parent 194b88e2eb
commit 897a6e5d5c
Signed by untrusted user: konrad
GPG Key ID: F40E70337AB24C9B
3 changed files with 10 additions and 11 deletions

View File

@ -22,6 +22,8 @@ import (
"strings" "strings"
"time" "time"
"code.vikunja.io/api/pkg/models"
"code.vikunja.io/api/pkg/user" "code.vikunja.io/api/pkg/user"
"code.vikunja.io/api/pkg/utils" "code.vikunja.io/api/pkg/utils"
) )
@ -62,7 +64,7 @@ type Todo struct {
DueDate time.Time DueDate time.Time
Duration time.Duration Duration time.Duration
RepeatAfter int64 RepeatAfter int64
RepeatMode string RepeatMode models.TaskRepeatMode
Created time.Time Created time.Time
Updated time.Time // last-mod Updated time.Time // last-mod
@ -227,8 +229,8 @@ CREATED:` + makeCalDavTimeFromTimeStamp(t.Created)
PRIORITY:` + strconv.Itoa(mapPriorityToCaldav(t.Priority)) PRIORITY:` + strconv.Itoa(mapPriorityToCaldav(t.Priority))
} }
if t.RepeatAfter > 0 || t.RepeatMode == "MONTHLY" { if t.RepeatAfter > 0 || t.RepeatMode == models.TaskRepeatModeMonth {
if t.RepeatMode == "MONTHLY" { if t.RepeatMode == models.TaskRepeatModeMonth {
caldavtodos += ` caldavtodos += `
RRULE:FREQ=MONTHLY;BYMONTHDAY=` + t.DueDate.Format("02") // Day of the month RRULE:FREQ=MONTHLY;BYMONTHDAY=` + t.DueDate.Format("02") // Day of the month
} else { } else {

View File

@ -20,6 +20,8 @@ import (
"testing" "testing"
"time" "time"
"code.vikunja.io/api/pkg/models"
"code.vikunja.io/api/pkg/config" "code.vikunja.io/api/pkg/config"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
@ -423,7 +425,7 @@ END:VCALENDAR`,
Description: "Lorem Ipsum", Description: "Lorem Ipsum",
UID: "randommduid", UID: "randommduid",
Timestamp: time.Unix(1543626724, 0).In(config.GetTimeZone()), Timestamp: time.Unix(1543626724, 0).In(config.GetTimeZone()),
RepeatMode: "MONTHLY", RepeatMode: models.TaskRepeatModeMonth,
DueDate: time.Unix(1543626724, 0).In(config.GetTimeZone()), DueDate: time.Unix(1543626724, 0).In(config.GetTimeZone()),
}, },
}, },
@ -458,7 +460,7 @@ END:VCALENDAR`,
Description: "Lorem Ipsum", Description: "Lorem Ipsum",
UID: "randommduid", UID: "randommduid",
Timestamp: time.Unix(1543626724, 0).In(config.GetTimeZone()), Timestamp: time.Unix(1543626724, 0).In(config.GetTimeZone()),
RepeatMode: "DEFAULT", RepeatMode: models.TaskRepeatModeDefault,
DueDate: time.Unix(1543626724, 0).In(config.GetTimeZone()), DueDate: time.Unix(1543626724, 0).In(config.GetTimeZone()),
RepeatAfter: 435, RepeatAfter: 435,
}, },

View File

@ -35,11 +35,6 @@ func GetCaldavTodosForTasks(list *models.ListWithTasksAndBuckets, listTasks []*m
duration := t.EndDate.Sub(t.StartDate) duration := t.EndDate.Sub(t.StartDate)
repeatMode := "DEFAULT"
if t.RepeatMode == models.TaskRepeatModeMonth {
repeatMode = "MONTHLY"
}
caldavtodos = append(caldavtodos, &Todo{ caldavtodos = append(caldavtodos, &Todo{
Timestamp: t.Updated, Timestamp: t.Updated,
UID: t.UID, UID: t.UID,
@ -55,7 +50,7 @@ func GetCaldavTodosForTasks(list *models.ListWithTasksAndBuckets, listTasks []*m
DueDate: t.DueDate, DueDate: t.DueDate,
Duration: duration, Duration: duration,
RepeatAfter: t.RepeatAfter, RepeatAfter: t.RepeatAfter,
RepeatMode: repeatMode, RepeatMode: t.RepeatMode,
}) })
} }