const timeScale = 15
// function nearNumber(num, scale) {
// let minDivide = parseInt(num / scale)
// return scale * (num % scale / scale > 0.5 ? minDivide + 1 : minDivide)
// }
// function neatTime(time, timeScale) {
// let currentMinute = dayjs(time).minute()
// let targetMinute = nearNumber(currentMinute, timeScale)
// return dayjs(time).set('minute', targetMinute)
// }
function timeStatus(timeScale, startTimeStr = "00:00", endTimeStr = "23:59") {
let startTime = dayjs(`2000-01-01 ${startTimeStr}`)
let endTime = dayjs(`2000-01-01 ${endTimeStr}`)
let timediff = Math.abs(startTime.diff(endTime, "m"))
let timeStatusCount = parseInt(timediff / timeScale)
let timeStatusStr = ""
for (let i = 0; i < timeStatusCount; i++) {
timeStatusStr += 0
}
return {
timeScale: timeScale,
startTime: startTimeStr,
endTime: endTimeStr,
timeStatusStr
}
}
function setTimeStatus(timeStatus, taskStartTimeStr = "01:00", taskEndTimeStr = "02:00") {
let taskStartTime = dayjs(`2000-01-01 ${taskStartTimeStr}`)
let taskEndTime = dayjs(`2000-01-01 ${taskEndTimeStr}`)
let startTime = dayjs(`2000-01-01 ${timeStatus.startTime}`)
let startDiffMins = Math.abs(taskStartTime.diff(startTime, 'm'))/timeStatus.timeScale
let endDiffMins = Math.abs(taskEndTime.diff(startTime, 'm'))/timeStatus.timeScale
console.log(startDiffMins)
console.log(endDiffMins)
for (let i = startDiffMins - 1; i < endDiffMins - 1; i++) {
if (timeStatus.timeStatusStr[i] === 1) consoe.error('任务覆盖')
console.info(i,timeStatus.timeStatusStr[i])
timeStatus.timeStatusStr[i] = 1
}
return timeStatus
}
let test1 = timeStatus(timeScale)
console.log(JSON.stringify(test1))
let test2 = setTimeStatus(test1)
console.log(JSON.stringify(test2))
// startTimeStr = "00:00"
// let dd = dayjs(`2000-01-01 ${startTimeStr}`)
// console.log(dd)
console