I’m trying to find all the dates that would form a whole week based on a single date.
So if the date is located in the middle of the week like a Wednesday, it would return Sunday, Monday, up to Saturday.
Here’s an example:
So let’s say I have Wed 10 Oct 2012.
I would pass this date object to the function and the function would return ['2012-10-07', '2012-10-08', '2012-10-09', '2012-10-10', '2012-10-11', '2012-10-12', '2012-10-13'] (I don’t want strings, but Date objects, strings are there just for the example ^^
I already tried myself, but the method I created is very long and dumb, here it is anyways: https://gist.github.com/3889121
But what I’m primarly looking for here is instructions. What to use, is there an easier way?
Thanks!
Here’s a function that returns an Array of Date instances from the first sunday before the given date until the next sunday:
Just for fun, a shorter version (a oneliner) using
Array.map, as an extension of theDate.prototype