From 99a2013767eb57806d6bc261fdd71de24e9e6c85 Mon Sep 17 00:00:00 2001 From: Keith Holliday Date: Thu, 18 May 2017 14:12:36 -0600 Subject: [PATCH] Fixed display of next due dates --- .../client-old/js/services/taskServices.js | 18 +++++++---- website/common/script/cron.js | 32 ++++++++++++++++--- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/website/client-old/js/services/taskServices.js b/website/client-old/js/services/taskServices.js index 0b7cc9b952..2c92acff33 100644 --- a/website/client-old/js/services/taskServices.js +++ b/website/client-old/js/services/taskServices.js @@ -263,6 +263,7 @@ angular.module('habitrpg') modalScope.task._tags = !user.preferences.tagsCollapsed; modalScope.task._advanced = !user.preferences.advancedCollapsed; modalScope.task._edit = angular.copy(task); + modalScope.user = user; if($rootScope.charts[task._id]) $rootScope.charts[task.id] = false; modalScope.taskStatus = taskStatus; @@ -294,7 +295,7 @@ angular.module('habitrpg') $scope.$watch('task._edit', function (newValue, oldValue) { if ($scope.task.type !== 'daily' || !task._edit) return; $scope.summary = generateSummary($scope.task); - $scope.nextDue = generateNextDue($scope.task); + $scope.nextDue = generateNextDue($scope.task._edit, $scope.user); $scope.repeatSuffix = generateRepeatSuffix($scope.task); if ($scope.task._edit.repeatsOn == 'dayOfMonth') { @@ -388,12 +389,15 @@ angular.module('habitrpg') } }; - function generateNextDue (task) { - if (!task.nextDue) return; - let nextDue = task.nextDue.map((date) => { - let dateObject = new Date(date); - return [dateObject.getFullYear(), dateObject.getMonth() + 1, dateObject.getDate()].join('-'); - }) + function generateNextDue (task, user) { + let options = angular.copy(user); + options.nextDue = true; + let nextDueDates = Shared.shouldDo(new Date, task, options); + + let nextDue = nextDueDates.map((date) => { + return date.format('MM-DD-YYYY'); + }); + return nextDue.join(', '); } diff --git a/website/common/script/cron.js b/website/common/script/cron.js index 042f89006f..513ac07ab4 100644 --- a/website/common/script/cron.js +++ b/website/common/script/cron.js @@ -122,7 +122,7 @@ export function shouldDo (day, dailyTask, options = {}) { let schedule = moment(startDate).recur() .every(dailyTask.everyX).days(); - if (options.nextDue) return schedule.fromDate(startOfDayWithCDSTime).next(3); + if (options.nextDue) return schedule.fromDate(startOfDayWithCDSTime).next(6); return schedule.matches(startOfDayWithCDSTime); } else if (dailyTask.frequency === 'weekly') { @@ -133,7 +133,15 @@ export function shouldDo (day, dailyTask, options = {}) { schedule = schedule.every(daysOfTheWeek).daysOfWeek(); - if (options.nextDue) return schedule.fromDate(startOfDayWithCDSTime).next(3); + if (options.nextDue) { + let dates = schedule.fromDate(startOfDayWithCDSTime).next(6); + let filterDates = dates.filter((momentDate) => { + let weekDiff = momentDate.week() - moment(startDate).week(); + let matchX = weekDiff % dailyTask.everyX === 0; + return matchX; + }); + return filterDates; + } return schedule.matches(startOfDayWithCDSTime) && matchEveryX; } else if (dailyTask.frequency === 'monthly') { @@ -149,7 +157,15 @@ export function shouldDo (day, dailyTask, options = {}) { schedule = schedule.every(dailyTask.daysOfMonth).daysOfMonth(); } - if (options.nextDue) return schedule.fromDate(startOfDayWithCDSTime).next(3); + if (options.nextDue) { + let dates = schedule.fromDate(startOfDayWithCDSTime).next(6); + let filterDates = dates.filter((momentDate) => { + let monthDiff = momentDate.month() - moment(startDate).month(); + let matchX = monthDiff % dailyTask.everyX === 0; + return matchX; + }); + return filterDates; + } return schedule.matches(startOfDayWithCDSTime) && matchEveryX; } else if (dailyTask.frequency === 'yearly') { @@ -157,7 +173,15 @@ export function shouldDo (day, dailyTask, options = {}) { schedule = schedule.every(dailyTask.everyX).years(); - if (options.nextDue) return schedule.fromDate(startOfDayWithCDSTime).next(3); + if (options.nextDue) { + let dates = schedule.fromDate(startOfDayWithCDSTime).next(6); + let filterDates = dates.filter((momentDate) => { + let monthDiff = momentDate.years() - moment(startDate).years(); + let matchX = monthDiff % dailyTask.everyX === 0; + return matchX; + }); + return filterDates; + } return schedule.matches(startOfDayWithCDSTime); }