export function defaultTime(num) {
  var date = new Date();
  var s1 =
    date.getFullYear() +
    num +
    "-" +
    (date.getMonth() + 1) +
    "-" +
    date.getDate() +
    " " +
    date.getHours() +
    ":" +
    date.getMinutes() +
    ":" +
    date.getSeconds();
  return s1;
}
// 校验时间格式
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),time);
  return pattern.test(time)
}
// 判断开始时间与结束时间
export function calculateTime(startTime, endTime) {
  let isPass = {
    isOk: true,
    incorrect: {
      err: "",
    },
  }
  let time = new Date().getTime()
  let newStartTime = (new Date(startTime).getTime())
  let 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;

}
