根据班制数据判断,你这没头没尾的。。。。让我一通追问才弄明白
data = [{
"end_date": "2023-05-20 10:58:46.0",
"trusday": "",
"saturday": "",
"sf_id": "797795276940116965",
"person_sex": "男",
"work_no": "2",
"frequency_name": "班次二",
"closing_time": "00:00:00",
"wednesday": "",
"friday": "",
"id": "846475598908882982",
"person_collection_id": "13a003bfc58d4b6483b834907beb5070",
"start_date": "2023-04-26 10:34:15.0",
"monday": "",
"station_name": "桥西区中转站",
"work_cycle": "1",
"create_time": "",
"rest_no": "1",
"station_id": "86b1d606baf04dba87230243b6aa2c2a",
"thursday": "",
"person_name": "张唐廷",
"person_age": "34",
"sunday": "",
"frequency_id": "797795276940116965",
"work_time": "04:00:00",
"organ_id": "57cbf560-7552-44a4-a726-8873a1fd8351"
},
{
"end_date": "2023-05-30 00:00:00.0",
"trusday": "0",
"saturday": "1",
"sf_id": "843471547225079872",
"person_sex": "男",
"work_no": "",
"frequency_name": "班次三",
"closing_time": "17:00:00",
"wednesday": "0",
"friday": "0",
"id": "825830464555057319",
"person_collection_id": "1c0d596547444cfba7b96669846ba568",
"start_date": "2023-05-01 00:00:00.0",
"monday": "0",
"station_name": "河东区中转站",
"work_cycle": "0",
"create_time": "",
"rest_no": "",
"station_id": "76303b4b78434fe8962b379f29fd53a3",
"thursday": "0",
"person_name": "赵六",
"person_age": "59",
"sunday": "1",
"frequency_id": "843471547225079872",
"work_time": "09:00:00",
"organ_id": "6ba42ba4-7114-4f84-b877-86a197bea261"
}]
for (var i = 0; i < data.length ; i ++ )
{
var e = new Date(data[i]['end_date'].replace(/\s+.*$/gi,''));
var s = new Date(data[i]['start_date'].replace(/\s+.*$/gi,''));
var days = (e - s) / 1000 / 60 / 60 / 24;
var b = data[i]['work_no'];
if (b.length > 0 && parseInt(b) > 0)
{
work = parseInt(b);
rest = parseInt(data[i]['rest_no']);
arr = Array.from(new Array(days)).map((x,y) => y % (work + rest) < work ? 1 : 0)
}else{
week = s.getDay();
bc = [data[i]['monday'],data[i]['trusday'],0,0,0,data[i]['saturday'],data[i]['sunday']]
arr = Array.from(new Array(days)).map((x,y) => bc[(y + week) % 7])
}
console.log(arr);
}