import moment from 'moment';
var dateFmt = 'YYYY-MM-DD';
var timeFmt = 'YYYY-MM-DD HH:mm:ss';
var timeMinuteFmt = 'YYYY-MM-DD HH:mm';
/**
 * new Date 解决ios 安卓兼容问题
 * @param {*} date 时间
 */

export var newDate = function newDate(date) {
  if (date instanceof Date) {
    return date;
  }

  if (date) {
    var reg = /^[0-9]+.?[0-9]*$/;

    if (reg.test(date)) {
      return new Date(Number(date));
    }

    return new Date(date.replace(/-/g, '/'));
  }

  return new Date();
};
export var formatDate = function formatDate(date) {
  return moment(date).format(dateFmt);
};
export var formatDateTime = function formatDateTime(time) {
  return moment(time).format(timeFmt);
};
export var formatDeteMinute = function formatDeteMinute(time) {
  return moment(time).format(timeMinuteFmt);
};
export function formatDayMonth(date) {
  var fmt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'DD MMM';

  if (!date) {
    return '';
  }

  return moment(newDate(date)).format(fmt);
}