Skip to content

Instantly share code, notes, and snippets.

@Cycymomo
Last active December 28, 2015 05:59
Show Gist options
  • Save Cycymomo/7453339 to your computer and use it in GitHub Desktop.
Save Cycymomo/7453339 to your computer and use it in GitHub Desktop.
getDaysInYear.js
function getDaysInYear(year,day){
var d=new Date(year,0), dates=[];
d.setDate(d.getDate()+(7+day-d.getDay())%7);
while(d.getFullYear()===year){
dates.push(new Date(d));
d.setDate(d.getDate()+7);
}
return dates;
}
function getDaysInYear(y,d,t,r){
for((t=new Date(y,r=[])).setDate(t.getDate()+(7+d-t.getDay())%7);t.getFullYear()==y;t.setDate(t.getDate()+7))r.push(new Date(t));return r
}
console.log( getDaysInYear(2014,2) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment