Closed hasyrails closed 4 years ago
getArray() {
const i = 0;
while (i <= this.schedules.length){
var dateArray[0] = [];
var currentDate[0] = moment(this.schedules[0].start_yyyymmdd);
var stopDate[0] = moment(this.schedules[0].end_yyyymmdd);
while (currentDate[0] <= stopDate[0]) {
dateArray[0].push( moment(currentDate).format('YYYY-MM-DD') )
currentDate[0] = moment(currentDate[0]).add(1, 'days');
}
}
console.log(dateArray);
},
currentDate[0]
のようなナンバリングは配列用
currentDate_0
のように変数名のナンバリングするには
数字と文字列の変換・結合をする必要がある → 配列を使う
var dateArray_0 = [];
var dateArray_1 = [];
while(dateArrays.length <= this.schedules.length-1){
dateArrays.push([]);
}
dateArray_0 ⇄ dateArrays[0]
dateArray_1 ⇄ dateArrays[1]
var currentDate_0 = moment(this.schedules[0].start_yyyymmdd);
var currentDate_1 = moment(this.schedules[1].start_yyyymmdd);
let i = 0;
while(i <= this.schedules.length-1){
currentDates.push(moment(this.schedules[i].start_yyyymmdd));
i = i + 1;
}
currentDate_0 ⇄ currentDates[0]
currentDate_1 ⇄ currentDates[1]
var stopDate_0 = moment(this.schedules[0].end_yyyymmdd);
var stopDate_1 = moment(this.schedules[1].end_yyyymmdd);
let j = 0;
while(j <= this.schedules.length-1){
stopDates.push(moment(this.schedules[j].end_yyyymmdd));
j = j + 1;
}
stopDate_0 ⇄ stopDates[0]
stopDate_1 ⇄ stopDates[1]
while (currentDate_0 <= stopDate_0) {
dateArray_0.push( moment(currentDate_0).format('YYYY-MM-DD') )
currentDate_0 = moment(currentDate_0).add(1, 'days');
}
while (currentDate_1 <= stopDate_1) {
dateArray_1.push( moment(currentDate_1).format('YYYY-MM-DD') )
currentDate_1 = moment(currentDate_1).add(1, 'days');
}
let k = 0;
while(k <= this.schedules.length -1){
while (currentDates[k] <= stopDates[k]) {
dateArrays[k].push( moment(currentDates[k]).format('YYYY-MM-DD') )
DatesContainer.push(dateArrays[k])
currentDates[k] = moment(currentDates[k]).add(1, 'days');
}
k = k + 1;
}
する/しないの選択をさせるには start(開始日)/end(終了日)を指定したタスクから 開始日,開始日の前日、‥,終了日の前日、終了日に 対応するタスクを新しく作る必要がある
Javascript-2つの日付の間の日付の配列を取得する
この処理をwhileループで実装する