Created
August 3, 2012 16:26
-
-
Save ear1grey/3249202 to your computer and use it in GitHub Desktop.
A tiny utility for creating a json array of dates 1 week apart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
A tiny utility for creating a json array of dates. | |
I need this for creating year-long timetables where after an initial start | |
we have a few weeks off for christmas, then easter, and these weeks differ | |
each year, so the 'switches' make it easy to include weeks (signified by a 1) | |
or exclude weeks (a 0) | |
Note that monts start at 0 not 1 :-) | |
*/ | |
var d, switches, num, weeks, week; | |
weeks = []; | |
d = new Date(2012, 8, 24); | |
switches = [1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,0,0,0,0,0,1,1]; | |
num = switches.reduce(function(p, c){ | |
return p + c; | |
}); | |
for (week = 0; week < 99; week++) { | |
// if the week is a "1" in the array of | |
if (switches[week] == 1) { | |
weeks.push( | |
d.toString() | |
); | |
} | |
// add seven days | |
d.setDate(d.getDate()+7); | |
} | |
console.log(weeks); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment