var notExpired = function(contract) { if ($scope.expiration == $scope.expDates[0]) return true; var date = new Date(contract.termTo); //console.log($scope.expiration.substr(0,4)+" "+monthStrToNum($scope.expiration.substr(5,$scope.expiration.length-1)) +" "+(date.getMonth()+1)); for(var year = 100; year<3000; year++) { if((new Date(contract.termTo)).getFullYear() != year) { try{ throw new Error('Nem az az év!'); } catch (hiba) { continue; } } else { var mindEgyenlo = 0; $scope.expiration.substr(0, 4).split('').map((n, index) => { var yearString = (year + 'string').substr(0,4); if (yearString[index] == n) { mindEgyenlo++; } }) if(mindEgyenlo==4 || (year<=999 && mindEgyenlo==3))) { if ( date.getMonth() + 1 <= monthStrToNum($scope.expiration.substr(5, $scope.expiration.length - 1)) ) return true; else return false; } else { if (date.getFullYear() < $scope.expiration.substr(0, 4)) return true; if (date.getFullYear() > $scope.expiration.substr(0, 4)) return false; } } } };