0

I have JSON Data which consist of Array of Data and I wanted to find the count tags based on this day, this week this month data

Plunker

In the JSON Data I am getting the date Format as

2017-08-10T13:14:53.000+0000
James Z
  • 12,209
  • 10
  • 24
  • 44
Mahesh G
  • 1,226
  • 4
  • 30
  • 57
  • what is your mean about _this day, this week, this month_? – Hadi J Aug 20 '17 at 17:07
  • I meant count of events which for today, which for this week, which is for this month like this.. Because here i just posted very small json data for reference but i have very huge JSON which will be containing the whole year data so – Mahesh G Aug 20 '17 at 17:12
  • i think this can help https://stackoverflow.com/a/20631750/8303694 – Jesus Carrasco Aug 20 '17 at 17:22

1 Answers1

1

Maybe help you. You should get day and week and month of base date as you see. then loop through data and get issue date ("created": "2017-08-10T13:14:53.000+0000") and create new date. so check it with base day,week, month of base date and go on.

var app = angular.module('myApp', []);

app.controller("Controller", ["$scope", "$http", "$filter", "$window",
  function($scope, $http, $filter, $window) {
    $scope.data = {
      "expand": "schema,names",
      "startAt": 0,
      "maxResults": 50,
      "total": 257,
      "issues": [{
          "expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
          "id": "1578077",
          "fields": {
            "created": "2017-08-10T13:14:53.000+0000",
            "resolutiondate": null,
            "status": {
              "name": "IN PROGRESS",
              "id": "10548"
            }
          }
        },
        {
          "expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
          "id": "1562078",
          "fields": {
            "created": "2017-07-27T03:42:24.000+0000",
            "resolutiondate": null,
            "status": {
              "name": "To Do",
              "id": "10548"
            }
          }
        },
        {
          "expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
          "id": "1562078",
          "fields": {
            "created": "2017-08-20T03:42:24.000+0000",
            "resolutiondate": null,
            "status": {
              "name": "To Do",
              "id": "10549"
            }
          }
        },
        {
          "expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
          "fields": {
            "created": "2017-08-11T13:03:52.000+0000",
            "resolutiondate": null,
            "status": {
              "name": "IN PROGRESS",
              "id": "3"
            }
          },
          "id": "1579217"
        }
      ]
    }
    var d = new Date("2017-08-10T13:14:53.000+0000");
    var day = d.getDay();
    var month = d.getMonth();
    $scope.dayCount = 0;
    $scope.monthEventCount = 0
    
    $scope.today = new Date();
    //var week = 
    $scope.findTheValue = function() {
      angular.forEach($scope.data.issues, function(issue) {
        var issueDate = new Date(issue.fields.created);
        if (issueDate.setHours(0,0,0,0) == $scope.today.setHours(0,0,0,0))
          $scope.dayCount = $scope.dayCount + 1;
        if (issueDate.getMonth() == month)
          $scope.monthEventCount = $scope.monthEventCount + 1;
      })
    }
  }
]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp">
  <div ng-controller="Controller">
    <button type="button" ng-click="findTheValue();">Submit</button>
    <div>{{dayCount}}</div>
    <div>{{monthEventCount}}</div>
    {{date}}
  </div>
</div>
Hadi J
  • 16,989
  • 4
  • 36
  • 62