DateFilters.js

angular.module('homepage').
// DATE filters
filter('datediff', function() {
	/**
	 * Get the difference of dates
	 * @param  {Object} attribute {'0': Date, '1': Date, type: 'String'}
	 * @return {Number}           Difference of date in hours/days
	 */
	return function(input, date1, date2) {
		var text = '';
		var suffix = '';
		var timestamp0 = new Date(date1).getTime();
		var timestamp1 = new Date(date2).getTime();
		var difference = Math.abs(timestamp0 - timestamp1) / 1000;
		
		if (difference < 60) {
			text = difference + ' sec';
		}
		else if (difference < 60*60) {
			difference = Math.floor(difference/60);
			text = difference + 'min'; 
		}
		else if (difference < 24*60*60) {
			difference = Math.floor(difference/(60*60));
			text = difference + ' hour';
		}

		suffix = difference == 1 ? '' : 's';

		return text + suffix;
	};
}).
filter('monthbyindex', function(DateUtility) {
	var months = DateUtility.getMonthTitles();
	return function(index) {
		return months[index];
	}
});