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
This commit is contained in:
Aquib Master
2017-11-16 05:32:30 +13:00
committed by Matteo Pagliazzi
parent 52064f6b2a
commit 46a8ee52d4

View File

@@ -595,13 +595,22 @@ export default {
if (this.task.type === 'habit' && (this.task.up || this.task.down)) return true; if (this.task.type === 'habit' && (this.task.up || this.task.down)) return true;
return false; 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 () { isDueOverdue () {
return moment().diff(this.task.date, 'days') >= 0; return this.timeTillDue.asDays() <= 0;
}, },
dueIn () { dueIn () {
// this.task && is necessary to make sure the computed property updates correctly const dueIn = this.timeTillDue.asDays() === 0 ?
const dueIn = moment().to(this.task && this.task.date); this.$t('today') :
return this.$t('dueIn', {dueIn}); this.timeTillDue.humanize(true);
return this.$t('dueIn', { dueIn });
}, },
hasTags () { hasTags () {
return this.task.tags && this.task.tags.length > 0; return this.task.tags && this.task.tags.length > 0;