export function defaultTime(num, dayNum = 0) {
  var change = new Date()
  change.setDate(change.getDate() + dayNum)
  console.log(num)
  console.log(change.getFullYear())
  var Y = change.getFullYear() + num + '-'
  var M = change.getMonth() + 1 + '-'
  var D =
    (change.getDate() < 10 ? '0' + change.getDate() : change.getDate()) + ' '
  var h =
    (change.getHours() < 10 ? '0' + change.getHours() : change.getHours()) +
    ':'
  var m =
    (change.getMinutes() < 10
      ? '0' + change.getMinutes()
      : change.getMinutes()) + ':'
  var s =
    change.getSeconds() < 10 ? '0' + change.getSeconds() : change.getSeconds()
  return Y + M + D + h + m + s
}
// 校验时间格式
export function checkTime(time) {
  var pattern =
    /([0-9]{3}[1-9]|[0-9][1-9][0-9]2022-01-07 19:29:33|[0-9]2022-01-07 19:29:33[1-9][0-9]|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8])))([ ])([0-1]?[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])/
  // console.log(pattern.test(time.trim()));
  return pattern.test(time)
}
// 判断开始时间与结束时间
export function calculateTime(startTime, endTime) {
  const isPass = {
    isOk: true,
    incorrect: {
      err: ''
    }
  }
  const time = new Date().getTime()
  const newStartTime = new Date(startTime).getTime()
  const newEndTime = new Date(endTime).getTime()
  if (newEndTime <= newStartTime) {
    isPass.isOk = false
    isPass.incorrect.err = '开始时间必须小于结束时间'
  } else if (newEndTime <= time) {
    isPass.isOk = false
    isPass.incorrect.err = '开始时间必须小于当前时间'
  }
  return isPass
}
