import moment from "moment/moment";
import _ from 'lodash'

const makeTime = (type) => {
  //
  const timeArr = moment().startOf(type).toArray();
  //年月日数组
  const ymdArr = _.slice(timeArr, 0, 3);
  //月份少1，加1
  ymdArr[1] = ymdArr[1] + 1;
  let newYmdArr = [];
  for (let i = 0; i < ymdArr.length; i++) {

    if (ymdArr[i].toString().length < 2) {
      const numT = "0" + ymdArr[i];
      newYmdArr.push(numT);
    } else {
      newYmdArr.push(ymdArr[i]);
    }
  }

  return _.join(newYmdArr, '');
}

//根据时间查询
export default (type, s, e) => {

  //  开始时间from,to当前时间
  let startTime;
  let endTime;
  if (type === "normal") {
    startTime = "";
    endTime = "";
  } else if (type === "self") {
    startTime = s;
    endTime = e;
  } else {
    //  from
    startTime = makeTime(type);
    endTime = makeTime("day");
  }

  return {startTime, endTime}
}
