'use strict';

function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }

var isUdf = _interopDefault(require('./isUdf'));
var getDayStartTime = _interopDefault(require('./getDayStartTime'));
var consts = require('./consts');

/**
 * 获取两个时间之前相差的天数
 * @param {Date|number|string} time1 时间1
 * @param {Date|number|string} time2 时间2，默认当天
 * @returns
 *
 * @example
 * getDaysBetween('2021-01-01', '2021-10-01'); // => 273
 */
function getDaysBetween(time1, time2) {
  if (isUdf(time1)) return NaN;
  var timeStamp1 = getDayStartTime(time1);
  if (Number.isNaN(timeStamp1)) return NaN;
  var timeStamp2 = getDayStartTime(time2);
  if (Number.isNaN(timeStamp2)) return NaN;
  return (timeStamp2 - timeStamp1) / consts.DAY_TIME;
}

module.exports = getDaysBetween;
