diff --git a/pkg/caldav/caldav.go b/pkg/caldav/caldav.go index 7d7b55df8..3431fb1ad 100644 --- a/pkg/caldav/caldav.go +++ b/pkg/caldav/caldav.go @@ -22,6 +22,8 @@ import ( "strings" "time" + "code.vikunja.io/api/pkg/models" + "code.vikunja.io/api/pkg/user" "code.vikunja.io/api/pkg/utils" ) @@ -57,10 +59,12 @@ type Todo struct { RelatedToUID string Color string - Start time.Time - End time.Time - DueDate time.Time - Duration time.Duration + Start time.Time + End time.Time + DueDate time.Time + Duration time.Duration + RepeatAfter int64 + RepeatMode models.TaskRepeatMode Created time.Time Updated time.Time // last-mod @@ -225,6 +229,16 @@ CREATED:` + makeCalDavTimeFromTimeStamp(t.Created) 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 += ` LAST-MODIFIED:` + makeCalDavTimeFromTimeStamp(t.Updated) diff --git a/pkg/caldav/caldav_test.go b/pkg/caldav/caldav_test.go index 5701d0fd7..f5e3ab13f 100644 --- a/pkg/caldav/caldav_test.go +++ b/pkg/caldav/caldav_test.go @@ -20,6 +20,8 @@ import ( "testing" "time" + "code.vikunja.io/api/pkg/models" + "code.vikunja.io/api/pkg/config" "github.com/stretchr/testify/assert" ) @@ -408,6 +410,77 @@ DESCRIPTION:Lorem Ipsum PRIORITY:9 LAST-MODIFIED:00010101T000000Z 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`, }, } diff --git a/pkg/caldav/parsing.go b/pkg/caldav/parsing.go index 2136ad2a2..d9c419086 100644 --- a/pkg/caldav/parsing.go +++ b/pkg/caldav/parsing.go @@ -42,13 +42,15 @@ func GetCaldavTodosForTasks(list *models.ListWithTasksAndBuckets, listTasks []*m Description: t.Description, Completed: t.DoneAt, // Organizer: &t.CreatedBy, // Disabled until we figure out how this works - Priority: t.Priority, - Start: t.StartDate, - End: t.EndDate, - Created: t.Created, - Updated: t.Updated, - DueDate: t.DueDate, - Duration: duration, + Priority: t.Priority, + Start: t.StartDate, + End: t.EndDate, + Created: t.Created, + Updated: t.Updated, + DueDate: t.DueDate, + Duration: duration, + RepeatAfter: t.RepeatAfter, + RepeatMode: t.RepeatMode, }) }