"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.formatDayMonth = formatDayMonth;
exports.formatDeteMinute = exports.formatDateTime = exports.formatDate = exports.newDate = void 0;

var _moment = _interopRequireDefault(require("moment"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

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 时间
 */

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();
};

exports.newDate = newDate;

var formatDate = function formatDate(date) {
  return (0, _moment["default"])(date).format(dateFmt);
};

exports.formatDate = formatDate;

var formatDateTime = function formatDateTime(time) {
  return (0, _moment["default"])(time).format(timeFmt);
};

exports.formatDateTime = formatDateTime;

var formatDeteMinute = function formatDeteMinute(time) {
  return (0, _moment["default"])(time).format(timeMinuteFmt);
};

exports.formatDeteMinute = formatDeteMinute;

function formatDayMonth(date) {
  var fmt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'DD MMM';

  if (!date) {
    return '';
  }

  return (0, _moment["default"])(newDate(date)).format(fmt);
}