const formatTime = (str) => {
  return str.slice(0, 4) + '.' + str.slice(4, 6) + '.' + str.slice(6, 8) + ' ' + str.slice(8, 10) + ':' + str.slice(10, 12)
}
const toHourMinute = (minutes) => {
  return (Math.floor(minutes / 60) >= 24 ? Math.floor(minutes / 60 / 24) + '天' + (Math.floor(minutes / 60 % 24)) : Math.floor(minutes / 60)) + '小时' + (minutes % 60) + '分'
}
const secondsToDay = (msd) => {
  var time = msd
  if (time > 60 && time < 60 * 60) {
    time = parseInt(time / 60.0) + '分钟'
  } else if (time >= 60 * 60 && time < 60 * 60 * 24) {
    time = parseInt(time / 3600.0) + '小时' + parseInt((parseFloat(time / 3600.0) -
              parseInt(time / 3600.0)) * 60) + '分钟'
  } else if (time >= 60 * 60 * 24) {
    time = parseInt(time / 3600 / 24) + '天' + parseInt((parseFloat(time / 3600 / 24) -
              parseInt(time / 3600 / 24)) * 24) + '小时' + parseInt((parseFloat(time / 3600.0) -
              parseInt(time / 3600.0)) * 60) + '分钟'
  } else {
    time = 1 + '分钟'
  }
  return time
}
// 转换成时间戳
const amendTime = (hms) => {
  let t = new Date(hms).getTime() / 1000
  return t
}
// 时间戳转换为2019-01-22 12:10:00
const date = (str) => {
  let date = str * 1000
  const dateObj = {
    year: new Date(date).getFullYear(),
    month: new Date(date).getMonth() + 1 > 9 ? new Date(date).getMonth() + 1 : `0${new Date(date).getMonth() + 1}`,
    day: new Date(date).getDate() > 9 ? new Date(date).getDate() : `0${new Date(date).getDate()}`,
    hour: new Date(date).getHours() > 9 ? new Date(date).getHours() : `0${new Date(date).getHours()}`,
    minutes: new Date(date).getMinutes() > 9 ? new Date(date).getMinutes() : `0${new Date(date).getMinutes()}`,
    seconds: new Date(date).getSeconds() > 9 ? new Date(date).getSeconds() : `0${new Date(date).getSeconds()}`
  }
  return dateObj.year + "" + dateObj.month + "" + dateObj.day + "" + dateObj.hour + "" + dateObj.minutes + "" + dateObj.seconds
}
module.exports = {
  formatTime,
  toHourMinute,
  secondsToDay,
  amendTime,
  date
}
