import dayjs from 'dayjs';
function formatNumber(num) {
    return num.toString().padStart(2, '0');
}
// 获取日期 时间 星期
export const initDate = () => {
  const now = dayjs(Date.now());
  const weekdayNumber = now.day();
  const weekdays = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
  return {
    dateNow: `${now.year()}年${now.month() + 1}月${now.date()}日`,
    timeNow: `${formatNumber(now.hour())}:${formatNumber(now.minute())}`,
    weekNow: `${weekdays[weekdayNumber]}`,
  };
};
/**
 * 数组data拆分为num个为一组的二维数组
 * @param {*} data 
 * @param {*} num 
 */
export  const initArray = (data, num = 7) => {
  const newArray = [];
  const len = data.length;
  if (len <= num) {
    newArray.push(data);
  } else {
    for (let i = 0, j = 0; i < data.length; i++) {
      if (i != 0 && i % num == 0) {
        ++j;
      }
      if (!newArray[j]) {
        newArray[j] = [];
      }
      newArray[j].push(data[i]);
    }
  }
  return newArray;
};