Commit a06f1446 authored by Alina Habibulina's avatar Alina Habibulina

+ shot date period

parent b0acfdc3
......@@ -125,86 +125,30 @@ var portal = {
},
main: function (view, model) {
function zeroCheck(num){
if (num < 10) {num = "0"+ num;}
return num;
};
var serverDateTime = portal.player.model.getModelWithId("ts_date_created").value;
var serverDate = serverDateTime.substr(0, serverDateTime.length - 9);
var serverWeekDay = new Date(serverDate).getDay();
var WeekDay = new Date(serverDateTime);
WeekDay = WeekDay.getDay();
var shift = 7 - WeekDay;
switch(serverWeekDay){
case 0:
portal.player.model.getModelWithId("ts_period_date_to").setValue(WeekCalculating(serverDate, 7)); //0 день воскресение прошлой недели
portal.player.model.getModelWithId("ts_period_date_from").setValue(WeekCalculating(serverDate, 1)); // 1й день пндк нашей недели
break;
case 1:
portal.player.model.getModelWithId("ts_period_date_to").setValue(WeekCalculating(serverDate, 6)); //0 день воскресение прошлой недели
portal.player.model.getModelWithId("ts_period_date_from").setValue(WeekCalculating(serverDate, 0)); // 1й день пндк нашей недели
break;
case 2:
portal.player.model.getModelWithId("ts_period_date_to").setValue(WeekCalculating(serverDate, 5)); //0 день воскресение прошлой недели
portal.player.model.getModelWithId("ts_period_date_from").setValue(WeekCalculating(serverDate, (-1))); // 1й день пндк нашей недели
break;
case 3:
portal.player.model.getModelWithId("ts_period_date_to").setValue(WeekCalculating(serverDate, 4)); //0 день воскресение прошлой недели
portal.player.model.getModelWithId("ts_period_date_from").setValue(WeekCalculating(serverDate, (-2))); // 1й день пндк нашей недели
break;
case 4:
portal.player.model.getModelWithId("ts_period_date_to").setValue(WeekCalculating(serverDate, 3)); //0 день воскресение прошлой недели
portal.player.model.getModelWithId("ts_period_date_from").setValue(WeekCalculating(serverDate, (-3))); // 1й день пндк нашей недели
break;
case 5:
portal.player.model.getModelWithId("ts_period_date_to").setValue(WeekCalculating(serverDate, 2)); //0 день воскресение прошлой недели
portal.player.model.getModelWithId("ts_period_date_from").setValue(WeekCalculating(serverDate, (-4))); // 1й день пндк нашей недели
break;
case 6:
portal.player.model.getModelWithId("ts_period_date_to").setValue(WeekCalculating(serverDate, 1)); //0 день воскресение прошлой недели
portal.player.model.getModelWithId("ts_period_date_from").setValue(WeekCalculating(serverDate, (-5))); // 1й день пндк нашей недели
break;
case 7:
portal.player.model.getModelWithId("ts_period_date_to").setValue(WeekCalculating(serverDate, 0)); //0 день воскресение прошлой недели
portal.player.model.getModelWithId("ts_period_date_from").setValue(WeekCalculating(serverDate, (-6))); // 1й день пндк нашей недели
break;
}
var sunday = new Date(serverDateTime);
sunday.setDate(sunday.getDate() + shift);
var monday = new Date(serverDateTime);
monday.setDate(sunday.getDate() - 6);
function WeekCalculating(fullDate, shift){
var year = fullDate.substr(0, (fullDate.length - 6));
var month = fullDate.substr(5, (fullDate.length));
month = month.substr(0, (month.length - 3));
var day = fullDate.substr(8, fullDate.length);
day = parseInt(day) + shift;
switch(month){
case "01":
case "03":
case "05":
case "07":
case "08":
case "10":
case "12":
if(parseInt(day) > 31) { month = parseInt(month) + 1; day = "01";}
break;
case "04":
case "06":
case "09":
case "11":
if(parseInt(day) > 30) { month = parseInt(month) + 1; day = "01";}
break;
case "02":
if((parseInt(year)%4 == 0) || (parseInt(year)%400 == 0)) {
if(parseInt(day) > 29) { month = parseInt(month) + 1; day = "01";}
} else {
if(parseInt(day) > 28) { month = parseInt(month) + 1; day = "01";}
}
break;
}
var StrSunday = sunday.getFullYear() + "-" + zeroCheck(sunday.getMonth()+1) + "-" + zeroCheck(sunday.getDate());
portal.player.model.getModelWithId("ts_period_date_to").setValue(StrSunday);
if((parseInt(month) + shift) > 12) { month = "01"; year = year + 1; } /////если месяцев больше 12, то увелививаем год
if(parseInt(day) < 10) day = "0" + day;
var finalDate = year + "-" + month + "-" + day;
return finalDate;
}
var StrMonday = monday.getFullYear() + "-" + zeroCheck(monday.getMonth()+1) + "-" + zeroCheck(monday.getDate());
portal.player.model.getModelWithId("ts_period_date_from").setValue(StrMonday);
}
};
//переменные для WaitCircles();
var currentTime = Date.now(),
r = 40,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment