Added assumption when no time is supplied (#8855)

* Added assumption when no time is supplied

* Changed format of date

* Set now options when date is specified
This commit is contained in:
Keith Holliday
2017-07-07 19:46:54 -06:00
committed by Sabe Jones
parent b3f9fd09c6
commit 3fa0b72ffe
3 changed files with 45 additions and 4 deletions

View File

@@ -26,10 +26,21 @@ async function _validateTaskAlias (tasks, res) {
export function setNextDue (task, user, dueDateOption) {
if (task.type !== 'daily') return;
let now = moment().toDate();
let dateTaskIsDue = Date.now();
if (dueDateOption) dateTaskIsDue = moment(dueDateOption);
if (dueDateOption) {
dateTaskIsDue = moment(dueDateOption);
// If not time is supplied. Let's assume we want start of Custom Day Start day.
if (dateTaskIsDue.hour() === 0 && dateTaskIsDue.minute() === 0 && dateTaskIsDue.second() === 0 && dateTaskIsDue.millisecond() === 0) {
dateTaskIsDue.add(user.preferences.dayStart, 'hours');
}
now = dateTaskIsDue;
}
let optionsForShouldDo = user.preferences.toObject();
optionsForShouldDo.now = now;
task.isDue = shared.shouldDo(dateTaskIsDue, task, optionsForShouldDo);
optionsForShouldDo.nextDue = true;
let nextDue = shared.shouldDo(dateTaskIsDue, task, optionsForShouldDo);
@@ -176,6 +187,12 @@ export async function getTasks (req, res, options = {}) {
let tasks = await mQuery.exec();
if (dueDate) {
tasks.forEach((task) => {
setNextDue(task, user, dueDate);
});
}
// Order tasks based on tasksOrder
if (type && type !== 'completedTodos' && type !== '_allCompletedTodos') {
let order = owner.tasksOrder[type];
@@ -190,8 +207,6 @@ export async function getTasks (req, res, options = {}) {
} else {
orderedTasks[i] = task;
}
if (dueDate) setNextDue(task, user, dueDate);
});
// Remove empty values from the array and add any unordered task