Я пытался найти " Расчет недели для данной даты " и не мог найти точное решение более простым способом.Вот что я попробовал:
Давайте предположим, что указанная дата равна 'd'
getWeekOfDay: function(d){
var date1 = new Date(d.getFullYear(), d.getMonth(), d.getDate());
var yearWeek;
var firstMondayOfWeek1 =
this.getMondayOfWeekOneOfAGivenYear(date1.getFullYear());
var weekNumber = Math.ceil((((date1 - firstMondayOfWeek1) / 86400000) + 1) / 7);
yearWeek = date1.getFullYear() + "." + weekNumber;
if(weekNumber <= 0 ){ // Jan 01 2012;
//date falls in last week of previous year
firstMondayOfWeek1 = this.getMondayOfWeekOneOfAGivenYear(date1.getFullYear() - 1);
weekNumber = Math.ceil((((date1 - firstMondayOfWeek1) / 86400000) + 1) / 7);
yearWeek = (date1.getFullYear() - 1) + "." + weekNumber;
}
if(weekNumber === 53 ){ // Dec 29 2014; Dec 28 2020
var Dec31 = new Date(date1.getFullYear(), 11, 31);
if(Dec31.getDay() < 4){
yearWeek = (date1.getFullYear() + 1) + "." + 1;
}
}
return yearWeek;
},
getMondayOfWeekOneOfAGivenYear: function(year){
//4th Jan always falls in Week1 of that year
var fouthJan = new Date(year, 0, 4);//
var day = fouthJan.getDay();
if (fouthJan.getDay() === 0) { //Sunday
day = 7;
}
var firstMondayofW1 = new Date(fouthJan);
firstMondayofW1.setDate(firstMondayofW1.getDate() + (1 - day) * 1);
return firstMondayofW1;
},