Skip to content

Instantly share code, notes, and snippets.

@RuffSeason
Created July 7, 2016 17:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RuffSeason/23b86b6a0cfa33f140a52e39130bf584 to your computer and use it in GitHub Desktop.
Save RuffSeason/23b86b6a0cfa33f140a52e39130bf584 to your computer and use it in GitHub Desktop.
Date Range Timestamps
var moment = require('moment');
// create truncated date ranges to fill with zeros
var enumerateDaysBetweenDates = function(startDate, endDate, granularity) {
var dates = [];
var currDate = startDate.clone().startOf(granularity);
var lastDate = endDate.clone().endOf(granularity);
while(currDate.add(granularity, 1).diff(lastDate) < 0) {
console.log(currDate.toDate());
dates.push(currDate.clone().toDate());
}
return dates;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment