Skip to content

Instantly share code, notes, and snippets.

@mu-777
Last active August 29, 2015 14:24
Show Gist options
  • Save mu-777/32ca29c693b6f2ad4dbd to your computer and use it in GitHub Desktop.
Save mu-777/32ca29c693b6f2ad4dbd to your computer and use it in GitHub Desktop.
function makeSameDayArr(targetDay, firstDate){
var targetDates = [],
targetDate = new Date(firstDate.getFullYear(),
firstDate.getMonth(),
1.0 + (7-(firstDate.getDay()-targetDay)%7)%7);
for(;targetDate.getMonth() == firstDate.getMonth();targetDate.setDate(targetDate.getDate()+7)){
targetDates.push(new Date(targetDate));
}
return targetDates;
}
var days = { 'sun': 0, 'mon': 1, 'tue': 2, 'wed': 3, 'thu': 4, 'fri':5, 'sat':6 };
console.log(makeSameDayArr(days['wed'], new Date(2015, 7-1, 1)));
// [ Wed Jul 01 2015 00:00:00 GMT+0900 (東京 (標準時)),
// Wed Jul 08 2015 00:00:00 GMT+0900 (東京 (標準時)),
// Wed Jul 15 2015 00:00:00 GMT+0900 (東京 (標準時)),
// Wed Jul 22 2015 00:00:00 GMT+0900 (東京 (標準時)),
// Wed Jul 29 2015 00:00:00 GMT+0900 (東京 (標準時)) ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment