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,7 +1289,13 @@ 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.
|
||||||
|
// The due date is used as a reference point for all new dates, so the
|
||||||
|
// behaviour depends on whether the due date is set at all.
|
||||||
|
if oldTask.DueDate.IsZero() {
|
||||||
|
// If a task has no due date, but does have a start and end date, the
|
||||||
|
// end date should keep the difference to the start date when setting
|
||||||
|
// them as new
|
||||||
if !oldTask.StartDate.IsZero() && !oldTask.EndDate.IsZero() {
|
if !oldTask.StartDate.IsZero() && !oldTask.EndDate.IsZero() {
|
||||||
diff := oldTask.EndDate.Sub(oldTask.StartDate)
|
diff := oldTask.EndDate.Sub(oldTask.StartDate)
|
||||||
newTask.StartDate = now.Add(repeatDuration)
|
newTask.StartDate = now.Add(repeatDuration)
|
||||||
|
@ -1303,6 +1309,21 @@ func setTaskDatesFromCurrentDateRepeat(oldTask, newTask *Task) {
|
||||||
newTask.EndDate = now.Add(repeatDuration)
|
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() {
|
||||||
|
diff := oldTask.DueDate.Sub(oldTask.EndDate)
|
||||||
|
newTask.EndDate = newTask.DueDate.Add(-diff)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
newTask.Done = false
|
newTask.Done = false
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue