fix: preserve dates for repeating tasks (#47)
Reviewed-At: https://github.com/go-vikunja/api/pull/47
This commit is contained in:
parent
d8f387f796
commit
090c67138a
1 changed files with 29 additions and 8 deletions
|
@ -1289,18 +1289,39 @@ func setTaskDatesFromCurrentDateRepeat(oldTask, newTask *Task) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If a task has a start and end date, the end date should keep the difference to the start date when setting them as new
|
// We want to preserve intervals among the due, start and end dates.
|
||||||
if !oldTask.StartDate.IsZero() && !oldTask.EndDate.IsZero() {
|
// The due date is used as a reference point for all new dates, so the
|
||||||
diff := oldTask.EndDate.Sub(oldTask.StartDate)
|
// behaviour depends on whether the due date is set at all.
|
||||||
newTask.StartDate = now.Add(repeatDuration)
|
if oldTask.DueDate.IsZero() {
|
||||||
newTask.EndDate = now.Add(repeatDuration + diff)
|
// If a task has no due date, but does have a start and end date, the
|
||||||
} else {
|
// end date should keep the difference to the start date when setting
|
||||||
if !oldTask.StartDate.IsZero() {
|
// them as new
|
||||||
|
if !oldTask.StartDate.IsZero() && !oldTask.EndDate.IsZero() {
|
||||||
|
diff := oldTask.EndDate.Sub(oldTask.StartDate)
|
||||||
newTask.StartDate = now.Add(repeatDuration)
|
newTask.StartDate = now.Add(repeatDuration)
|
||||||
|
newTask.EndDate = now.Add(repeatDuration + diff)
|
||||||
|
} else {
|
||||||
|
if !oldTask.StartDate.IsZero() {
|
||||||
|
newTask.StartDate = now.Add(repeatDuration)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !oldTask.EndDate.IsZero() {
|
||||||
|
newTask.EndDate = now.Add(repeatDuration)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// If the old task has a start and due date, we set the new start date
|
||||||
|
// to preserve the interval between them.
|
||||||
|
if !oldTask.StartDate.IsZero() {
|
||||||
|
diff := oldTask.DueDate.Sub(oldTask.StartDate)
|
||||||
|
newTask.StartDate = newTask.DueDate.Add(-diff)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the old task has an end and due date, we set the new end date
|
||||||
|
// to preserve the interval between them.
|
||||||
if !oldTask.EndDate.IsZero() {
|
if !oldTask.EndDate.IsZero() {
|
||||||
newTask.EndDate = now.Add(repeatDuration)
|
diff := oldTask.DueDate.Sub(oldTask.EndDate)
|
||||||
|
newTask.EndDate = newTask.DueDate.Add(-diff)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue