Experience
by Kunal Paul
HTML
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js"></script>
<div ng-app="myApp" ng-controller="MainCtrl">
<table ng-table="talentPoolList" show-filter="true" class="table table-striped table-bordered">
<th>
<tr>
<td>Career Started On</td>
<td align="center">Experience</td>
</tr>
</th>
<tr ng-repeat="employee in data">
<td>
{{employee.careerStartedOn | date: 'yyyy/MM/dd'}}
</td>
<td align="center">
{{getExp(employee.careerStartedOn)}}
</td>
</tr>
</table>
</div>
JavaScript
var myApp = angular.module('myApp', []);
myApp.controller('MainCtrl', function($scope,$filter) {
$scope.data = [
{
"careerStartedOn" : "2016-10-03T13:44:00.587"
},
{
"careerStartedOn" : "2015-10-03T13:44:00.587"
},
{
"careerStartedOn" : "2012-10-03T13:44:00.587"
}
];
$scope.CalDate = function(date1,date2) {
var diff = Math.floor(date1.getTime() - date2.getTime());
var secs = Math.floor(diff/1000);
var mins = Math.floor(secs/60);
var hours = Math.floor(mins/60);
var days = Math.floor(hours/24);
var months = Math.floor(days/31);
var years = Math.floor(months/12);
months=Math.floor(months%12);
days = Math.floor(days%31);
hours = Math.floor(hours%24);
mins = Math.floor(mins%60);
secs = Math.floor(secs%60);
var message = "";
if(days<=0){
message += secs + " sec ";
message += mins + " min ";
message += hours + " hours ";
}else{
if(years>0){
message += years + " years ";
}
if(months>0 || years>0){
message += months + " months ";
}
message += days + " days";
}
return message
};
$scope.getExp = function(date)
{
date = new Date($filter('date')(date, "yyyy/MM/dd"));
var currdate = new Date($filter('date')(new Date(), "yyyy/MM/dd"));
var exp = $scope.CalDate(currdate,date);
return exp;
}
});