Skip to content

Instantly share code, notes, and snippets.

@sreeix
Created June 26, 2011 18:06
Show Gist options
  • Save sreeix/1047810 to your computer and use it in GitHub Desktop.
Save sreeix/1047810 to your computer and use it in GitHub Desktop.
View to check overlap
function(doc) {
if (doc.type && doc.type === 'commission' && doc.affiliate_network && doc.begins && doc.ends) {
var current = doc.begins.split(/-/);
var ends = doc.ends.split(/-/);
var current_date = new Date(parseInt(current[0], 10), parseInt(current[1], 10) - 1, parseInt(current[2], 10) + 1); // javascript month starts at 0
var ends_date = new Date(parseInt(ends[0], 10), parseInt(ends[1], 10) - 1, parseInt(ends[2], 10) + 1); // javascript month starts at 0
while( current_date < ends_date){
emit([doc.network, doc.provider, current_date.getFullYear(), current_date.getMonth()+1, current_date.getDate()], null);
current_date = new Date(current_date.getTime() + 86400000);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment