Skip to content

Instantly share code, notes, and snippets.

@ashteya
Created July 2, 2015 21:01
Show Gist options
  • Select an option

  • Save ashteya/aa668aa914a3444da017 to your computer and use it in GitHub Desktop.

Select an option

Save ashteya/aa668aa914a3444da017 to your computer and use it in GitHub Desktop.
Group By Day In Collection-Repeat
.filter('groupByDayMonthYear', function($parse) {
var dividers = {};
return function(input) {
if (!input || !input.length) return;
var output = [],
previousDate,
currentDate;
for (var i = 0, ii = input.length; i < ii && (item = input[i]); i++) {
currentDate = moment(item.Date);
if (!previousDate ||
!currentDate.isSame(previousDate)) {
var dividerId = currentDate.format('DDMMYYYY');
if (!dividers[dividerId]) {
dividers[dividerId] = {
isDivider: true,
_id: dividerId,
divider: currentDate.format('DD MMMM YYYY')
};
}
output.push(dividers[dividerId]);
}
output.push(item);
previousDate = currentDate;
}
return output;
};
})
@ashteya
Copy link
Author

ashteya commented Jul 2, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment