I want a javascript function that will give the current weeknumber, then, when it has the weeknumber, get all the weeknumbers from current weeknumber - X and the same with the future, but: The currentweek has to be in the center! Examples:
Currentweek: 39, X: 3 the method should return: [38,39, 40]
Currentweek: 20 X: 4 the method should return: [18,19,20,21]
This seems really simple but: keep in mind that leap years can occur, also some years have 53 weeks
also, x can range from 3 to 30
Because this concept is a little hard to explain i have made a simplistic image:
Purpose: This will be used in a calendar sort of app, in which you scroll through weeks.
My attempts so far:
Get current week number (has worked so far, but i don't know if it'll work in 2015)
Date.prototype.getWeek = function() {
var onejan = new Date(this.getFullYear(), 0, 1);
var weekNumber = Math.ceil((((this - onejan) / 86400000) + onejan.getDay() + 1) / 7);
return weekNumber; }
Determine place in array for the current weeknumber:
myActiveSlide = Math.floor(X/2);
If even, this will round upwards, so for example, X = 4, it will return 3 as the center,
If uneven, this will give the exact center, for example: X = 3 it will return 2 as the center
That's as far as I've got, can't figure out the leap-year problems