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

//日期转时间戳

// 转换成月日转换
function formatemd(date) {
  date = getDate(+date)
  var year = date.getFullYear()
  var month = date.getMonth() + 1
  var day = date.getDate()
  var hour = date.getHours()
  var minute = date.getMinutes()
  var second = date.getSeconds()
  return formatNumber(month) + "." + formatNumber(day)

}

function checkAddZone(num) {
  return num < 10 ? '0' + num.toString() : num
}

// 时间戳转成年月日时分秒
function formateDay(date) {
  date = getDate(+date)
  var year = date.getFullYear()
  var month = date.getMonth() + 1
  var day = date.getDate()

  var hour = date.getHours()
  hour = checkAddZone(hour)
  var min = date.getMinutes()
  min = checkAddZone(min)
  var se = date.getSeconds()
  se = checkAddZone(se)
  return date.getFullYear() + "-" + formatNumber(date.getMonth() + 1) + "-" + formatNumber(date.getDate()) + ' ' + hour + ':' + min + ':' + se;
}
// 时间戳转成年月
function formateym(date, split = ".") {
  date = getDate(+date)
  var year = date.getFullYear()
  var month = date.getMonth() + 1
  var day = date.getDate()
  return date.getFullYear() + split + formatNumber(date.getMonth() + 1)
}

//逗号分隔字符串
function splitStr(strArr, separator) {
  if (!strArr || !separator) {
    return '';
  }
  strArr = strArr.substring(0, strArr.length - 1);
  return strArr.split(separator + '')
}

//逗号分隔字符串
function splitStr1(strArr, separator) {
  if (!strArr || !separator) {
    return '';
  }
  return strArr.split(separator + '')
}

function subStr(strArr) {
  if (!strArr) {
    return '';
  }
  return strArr.substring(0, 10);
}

// 获取图片链接
function formatUrl(url) {
  if (url) {
    // var root = require('../config/config.js')
    if (url.indexOf('http://') !== -1 || url.indexOf('https://') !== -1) {
      return url
    }
    return "https://hpjobtest.oss-cn-shanghai.aliyuncs.com" + url
  }
}

// 时间格式化
function formatTime(date, month_str, minute_str, status) {
  if (!date) {
    return 0
  }
  var _date = null;
  _date = getDate(date);
  var year = _date.getFullYear();
  var month = _date.getMonth() + 1;
  var day = _date.getDate();
  var hour = _date.getHours();
  var minute = _date.getMinutes();
  var second = _date.getSeconds();
  if (status) {
    return [year, month, day].map(formatNumber).join(month_str || '/')
  }
  return [year, month, day].map(formatNumber).join(month_str || '/') + ' ' + [hour, minute, second].map(formatNumber).join(minute_str || ':');
}

// 限定大小范围
function limitedSize(number, limit) {
  var _num = number - 0;
  var _limt = limit - 0;
  return _num > _limt ? _limt : _num;
}

function formatDate(date, month_str, minute_str) {
  if (!date) {
    return 0
  }
  date = date.replace(getRegExp('-', 'g'), '/');
  var _date = null;
  _date = getDate(date);
  var month = _date.getMonth() + 1;
  var day = _date.getDate();
  return month + '月' + day + '日';
}
module.exports = {
  formatemd: formatemd,
  splitStr: splitStr,
  formateym: formateym,
  splitStr1: splitStr1,
  subStr: subStr,
  formateDay: formateDay,
  formatUrl: formatUrl,
  formatTime: formatTime,
  limitedSize: limitedSize,
  formatDate: formatDate
};