fix(caldav): use const for repeat modes

This commit is contained in:
kolaente 2022-12-24 14:34:59 +01:00
parent bffbc9492f
commit 446525837c
Signed by untrusted user: konrad
GPG Key ID: F40E70337AB24C9B
3 changed files with 100 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"
) )
@ -57,10 +59,12 @@ type Todo struct {
RelatedToUID string RelatedToUID string
Color string Color string
Start time.Time Start time.Time
End time.Time End time.Time
DueDate time.Time DueDate time.Time
Duration time.Duration Duration time.Duration
RepeatAfter int64
RepeatMode models.TaskRepeatMode
Created time.Time Created time.Time
Updated time.Time // last-mod Updated time.Time // last-mod
@ -225,6 +229,16 @@ CREATED:` + makeCalDavTimeFromTimeStamp(t.Created)
PRIORITY:` + strconv.Itoa(mapPriorityToCaldav(t.Priority)) PRIORITY:` + strconv.Itoa(mapPriorityToCaldav(t.Priority))
} }
if t.RepeatAfter > 0 || t.RepeatMode == models.TaskRepeatModeMonth {
if t.RepeatMode == models.TaskRepeatModeMonth {
caldavtodos += `
RRULE:FREQ=MONTHLY;BYMONTHDAY=` + t.DueDate.Format("02") // Day of the month
} else {
caldavtodos += `
RRULE:FREQ=SECONDLY;INTERVAL=` + strconv.FormatInt(t.RepeatAfter, 10)
}
}
caldavtodos += ` caldavtodos += `
LAST-MODIFIED:` + makeCalDavTimeFromTimeStamp(t.Updated) LAST-MODIFIED:` + makeCalDavTimeFromTimeStamp(t.Updated)

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"
) )
@ -408,6 +410,77 @@ DESCRIPTION:Lorem Ipsum
PRIORITY:9 PRIORITY:9
LAST-MODIFIED:00010101T000000Z LAST-MODIFIED:00010101T000000Z
END:VTODO END:VTODO
END:VCALENDAR`,
},
{
name: "with repeating monthly",
args: args{
config: &Config{
Name: "test",
ProdID: "RandomProdID which is not random",
},
todos: []*Todo{
{
Summary: "Todo #1",
Description: "Lorem Ipsum",
UID: "randommduid",
Timestamp: time.Unix(1543626724, 0).In(config.GetTimeZone()),
RepeatMode: models.TaskRepeatModeMonth,
DueDate: time.Unix(1543626724, 0).In(config.GetTimeZone()),
},
},
},
wantCaldavtasks: `BEGIN:VCALENDAR
VERSION:2.0
METHOD:PUBLISH
X-PUBLISHED-TTL:PT4H
X-WR-CALNAME:test
PRODID:-//RandomProdID which is not random//EN
BEGIN:VTODO
UID:randommduid
DTSTAMP:20181201T011204Z
SUMMARY:Todo #1
DESCRIPTION:Lorem Ipsum
DUE:20181201T011204Z
RRULE:FREQ=MONTHLY;BYMONTHDAY=01
LAST-MODIFIED:00010101T000000Z
END:VTODO
END:VCALENDAR`,
},
{
name: "with repeat mode default",
args: args{
config: &Config{
Name: "test",
ProdID: "RandomProdID which is not random",
},
todos: []*Todo{
{
Summary: "Todo #1",
Description: "Lorem Ipsum",
UID: "randommduid",
Timestamp: time.Unix(1543626724, 0).In(config.GetTimeZone()),
RepeatMode: models.TaskRepeatModeDefault,
DueDate: time.Unix(1543626724, 0).In(config.GetTimeZone()),
RepeatAfter: 435,
},
},
},
wantCaldavtasks: `BEGIN:VCALENDAR
VERSION:2.0
METHOD:PUBLISH
X-PUBLISHED-TTL:PT4H
X-WR-CALNAME:test
PRODID:-//RandomProdID which is not random//EN
BEGIN:VTODO
UID:randommduid
DTSTAMP:20181201T011204Z
SUMMARY:Todo #1
DESCRIPTION:Lorem Ipsum
DUE:20181201T011204Z
RRULE:FREQ=SECONDLY;INTERVAL=435
LAST-MODIFIED:00010101T000000Z
END:VTODO
END:VCALENDAR`, END:VCALENDAR`,
}, },
} }

View File

@ -42,13 +42,15 @@ func GetCaldavTodosForTasks(list *models.ListWithTasksAndBuckets, listTasks []*m
Description: t.Description, Description: t.Description,
Completed: t.DoneAt, Completed: t.DoneAt,
// Organizer: &t.CreatedBy, // Disabled until we figure out how this works // Organizer: &t.CreatedBy, // Disabled until we figure out how this works
Priority: t.Priority, Priority: t.Priority,
Start: t.StartDate, Start: t.StartDate,
End: t.EndDate, End: t.EndDate,
Created: t.Created, Created: t.Created,
Updated: t.Updated, Updated: t.Updated,
DueDate: t.DueDate, DueDate: t.DueDate,
Duration: duration, Duration: duration,
RepeatAfter: t.RepeatAfter,
RepeatMode: t.RepeatMode,
}) })
} }