/**
 * 根据date类型返回相应格式日期时间
 */
const getComDate = (date,dateType) =>{
//null,ymdhms,yymmdd,yy-mm-dd,yy/mm/dd,yy,mm,dd,hhmmss
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()
  // console.log(year + ',' + month + ',' + day + ',' + hour + ',' + minute + ','+second)
  var returnDate
  if (dateType == 'null'){
    returnDate = year + '年' + month + '月' + day + '日' + [hour, minute, second].map(formatNumber).join(':')
  } 
  else if (dateType == 'ymdhms'){
    returnDate = [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute, second].map(formatNumber).join(':')
  } else if (dateType == 'yymmdd') {
    returnDate = [year, month, day].map(formatNumber).join('')
  } else if (dateType == 'yy-mm-dd') {
    returnDate = [year, month, day].map(formatNumber).join('-')
  } else if (dateType == 'yy') {
    returnDate = year
  }else if (dateType == 'mm') {
    returnDate = month
  } else if (dateType == 'dd') {
    returnDate = day
  } else if (dateType == 'hhmmss'){
    returnDate = [hour, minute, second].map(formatNumber).join(':')
  } else if (dateType == 'yy/mm/dd hh:mm:ss'){
    returnDate = [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
  }else if(dateType == 'yy-mm'){
    returnDate = [year, month].map(formatNumber).join('-')
  }
  return returnDate
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}

module.exports = {
  getComDate: getComDate
}
