// 比较日期，时间大小
export function compareCalendar(t1, t2) {
  if (t1.indexOf(' ') !== -1 && t2.indexOf(' ') !== -1) {
    // 包含时间，日期
    return compareTime(t1, t2)
  } else {
    // 不包含时间，只包含日期
    return compareDate(t1, t2)
  }
}

// 比较日期大小
function compareDate(logintime, logouttime) {
  var arys1 = []
  var arys2 = []
  if (logintime != null && logouttime != null) {
    arys1 = logintime.split('-')
    var logindate = new Date(arys1[0], parseInt(arys1[1] - 1), arys1[2])
    arys2 = logouttime.split('-')
    var logoutdate = new Date(arys2[0], parseInt(arys2[1] - 1), arys2[2])
    if (logindate > logoutdate) {
      return -1
    } else if (logindate === logoutdate) {
      return 0
    } else {
      return 1
    }
  }
}

// 判断日期，时间大小
function compareTime(logintime, logouttime) {
  if (logintime.length > 0 && logouttime.length > 0) {
    var logintimeTemp = logintime.split(' ')
    var logouttimeTemp = logouttime.split(' ')

    var arrloginDate = logintimeTemp[0].split('-')
    var arrlogoutDate = logouttimeTemp[0].split('-')

    var arrloginTime = logintimeTemp[1].split(':')
    var arrlogoutTime = logouttimeTemp[1].split(':')

    var allLoginDate = new Date(arrloginDate[0], arrloginDate[1], arrloginDate[2], arrloginTime[0], arrloginTime[1], arrloginTime[2])
    var allLogoutDate = new Date(arrlogoutDate[0], arrlogoutDate[1], arrlogoutDate[2], arrlogoutTime[0], arrlogoutTime[1], arrlogoutTime[2])

    if (allLoginDate.getTime() > allLogoutDate.getTime()) {
      return -1
    } else if (allLoginDate.getTime() === allLogoutDate.getTime()) {
      return 0
    } else {
      return 1
    }
  } else {
    return -1
  }
}
