Click here to Skip to main content
15,921,174 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm making a task management widget that displays tasks based on if they are in the current day, week or month. I'd like to push dates into weeklyTaskArray, dailyTaskArray, monthlyTaskArray and render them using .length.

What I have tried:

JavaScript
$http({
            method: 'GET',
            url: 'http://localhost:3000/api/tasks.json',
            // responseType: "json"
        }).then(function(response) {
            let tasks = response.data;
            angular.copy(tasks, taskArray)
            tasks.filter(function(element) {
                if (`${element.due_date} === "5/17/16" && ${element.due_date} === "5/19/16"`) {
                  console.log("in the function",element.due_date);
                  angular.copy(element, weeklyTaskArray);
                  console.log("this is the task array", weeklyTaskArray.length);
                } else if (element.due_date === "5/20/17") {
                  angular.copy(element, monthlyTaskArray);
                } else if (element.due_date === "5/15/17") {
                  angular.copy(element, dailyTaskArray);
                }
            })
        });



The function above pushes the entire data set into the weeklyTaskArray. Here is the data set:
JavaScript
[
  {
        "id": 1,
        "name": "Test Task",
        "due_date": "5/17/2016"
    },
    {
        "id": 2,
        "name": "Atlatl Task",
        "due_date": "5/19/2016"
    },
    {
        "id": 3,
        "name": "PriceBooks Task",
        "due_date": "5/20/2016"
    }
]
Posted
Updated 16-Sep-16 4:38am
v2

1 solution

I would suggest you to use moment js.
As you already know the dateformat. Parse it to a moment obj using the parser
Then you can compare and do lot of stuff with date

Check this out-
Moment.js | Docs[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900