From 46a8ee52d4fbafa02aaf3d5213144cb934b4ae64 Mon Sep 17 00:00:00 2001 From: Aquib Master Date: Thu, 16 Nov 2017 05:32:30 +1300 Subject: [PATCH] Modify relative dueIn time on tasks to be in days (#9251) * Modify relative dueIn time on tasks to be in days - Normalizes the current time and task due time to the ends of their respective days. - Returns 'today' if the dates are the same day else uses moment's humanize function to allow for weeks, months, years and so on. * Modify task due date to appear grey when due the next day --- website/client/components/tasks/task.vue | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/website/client/components/tasks/task.vue b/website/client/components/tasks/task.vue index 84b1a84421..39d74ef6ee 100644 --- a/website/client/components/tasks/task.vue +++ b/website/client/components/tasks/task.vue @@ -595,13 +595,22 @@ export default { if (this.task.type === 'habit' && (this.task.up || this.task.down)) return true; return false; }, + timeTillDue () { + // this.task && is necessary to make sure the computed property updates correctly + const endOfToday = moment().endOf('day'); + const endOfDueDate = moment(this.task && this.task.date).endOf('day'); + + return moment.duration(endOfDueDate.diff(endOfToday)); + }, isDueOverdue () { - return moment().diff(this.task.date, 'days') >= 0; + return this.timeTillDue.asDays() <= 0; }, dueIn () { - // this.task && is necessary to make sure the computed property updates correctly - const dueIn = moment().to(this.task && this.task.date); - return this.$t('dueIn', {dueIn}); + const dueIn = this.timeTillDue.asDays() === 0 ? + this.$t('today') : + this.timeTillDue.humanize(true); + + return this.$t('dueIn', { dueIn }); }, hasTags () { return this.task.tags && this.task.tags.length > 0;