Skip to content

Instantly share code, notes, and snippets.

@mnowick
Forked from joshorvis/datefilter.js
Last active August 29, 2015 14:00
Show Gist options
  • Save mnowick/28847197dfebdcac98e9 to your computer and use it in GitHub Desktop.
Save mnowick/28847197dfebdcac98e9 to your computer and use it in GitHub Desktop.
app.filter('daterange', function () {
return function(items,start_date, end_date) {
var result = [];
// date filters
var start_date = (start_date && !isNaN(Date.parse(start_date))) ? Date.parse(start_date) : 0;
var end_date = (end_date && !isNaN(Date.parse(end_date))) ? Date.parse(end_date) : new Date().getTime();
// if the items are loaded
if (items && items.length > 0) {
angular.forEach(items, function (item,index) {
var itemDate = new Date(item.date);
if (itemDate >= start_date && itemDate <= end_date) {
result.push(item);
}
});
return result;
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment