I am developing an advanced Angular To-Do App, which can be viewed here: https://personal-organizer.herokuapp.com/
The App is almost finished, I am just working on displaying the tasks in the "Overdue", "Due Today" and "Due Later" sections within the List state.
To achieve that, I am generating Today's date in the controller, and then I am comparing it to the Task date - placing the task in the appropriate section according to the result of the date comparison.
This is my controller, where I am creating today's date:
function ListCtrl(library) {
var vm = this;
vm.tasks = []; // array with all tasks
library.getTask(vm.tasks); // filling the array with data from database
console.log(vm.tasks);
vm.today = new Date().toISOString(); // generating today's date
console.log(vm.today);
}
And this is my HTML file, where I make the date comparison to display the tasks on their appropriate sections on the page:
<div class="overdue">
<div class="alert-danger head">OVERDUE</div>
<br>
<task-content ng-repeat="task in ListVM.tasks"
task-data="task"
ng-if="task.completed === false && task.date < ListVM.today">
</task-content>
</div>
<div class="today">
<div class="alert-warning head">DUE TODAY</div>
<br>
<task-content ng-repeat="task in ListVM.tasks"
task-data="task"
ng-if="task.completed === false && task.date === ListVM.today"">
</task-content>
</div>
<div class="later">
<div class="alert-success head">DUE LATER</div>
<br>
<task-content ng-repeat="task in ListVM.tasks"
task-data="task"
ng-if="task.completed === false && task.date > ListVM.today">
</task-content>
</div>
By console logging today's date (vm.today), I am getting an ISO string: 2017-10-31T17:31:23.770Z
And, by console logging my task array, which is stored in a mongo database, the result object is as follows:
0:{_id: "59f42085c4efd11d743dd739", todo: "Build another App", date: "2017-10-29T04:00:00.000Z", completed: true, __v: 0, …}
1:{_id: "59efa6440667b62c30028932", todo: "Update Portfolio", date: "2017-11-04T04:00:00.000Z", completed: true, __v: 0, …}
2:{_id: "59f8077a33e2680012bdb190", todo: "Mobile Design", date: "2017-11-10T05:00:00.000Z", completed: false, __v: 0, …}
3:{_id: "59f4cbc487bfab0012cb832b", todo: "Travel to Brazil", date: "2017-11-15T05:00:00.000Z", completed: false, __v: 0, …}
Now, this were the problem is. Every time I reload the page and generate a new Today date, the "TxxxZ" part of the string is different.
That makes it impossible to find a Today date that is equal to the Task date in the database. Even though the day, month and year are the same, the "TxxxZ" part of the string will be different.
Is there any way I can format the Today date and Task date strings, cutting out the "TxxxZ" part - so only the day, month and year are compared?
Or is there another more efficient way to compare these dates and achieve the desired result?
*** This question was flagged as a duplicate, but the suggested answer for the other question, the method setHours() does not work for dates as ISO Strings - and I need to compare both dates in that format.