TimelineService.js

angular.module('homepage').
// Store templates, location and widget data
factory('TimelineService', function (ArrayUtility, DateUtility) {
	var sortOrder = 'ASCDG';
	var isLoading = {
		value: false
	};
	function getItemsByDate(items, date) {
		var filtered = [];
		var givenDate = DateUtility.getDateOnly(new Date(date));

		for(var index in items) {
			var item = items[index];

			var submitDate = DateUtility.getDateOnly(new Date(item.timestamp));
			if(givenDate.getTime() == submitDate.getTime()) {
				filtered.push(item);
			}
		}

		return filtered;
	}

	function getSortOrder() {
		return sortOrder;
	}

	function setSortOrder() {
		sortOrder = (sortOrder === 'ASCDG') ? 'DSCDG' : 'ASCDG';
	}

	function getLoadingStatus() {
		return isLoading;
	}

	function setLoadingStatus(value) {
		isLoading.value = value;
	}

	return {
		getSortOrder: getSortOrder,
		setSortOrder: setSortOrder,
		getLoadingStatus: getLoadingStatus,
		setLoadingStatus: setLoadingStatus,
		getItemsByDate: getItemsByDate
	};
});