'use strict';

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

var isUdf = _interopDefault(require('./isUdf'));
var formatToDate = _interopDefault(require('./formatToDate'));

/**
 * 获取某年某月的天数
 * @param {*} time
 * @returns {number}
 *
 * getMonthDays('2021-2');            // => 28
 * getMonthDays('2021-03');           // => 31
 * getMonthDays(1617235200000);       // => 30
 * getMonthDays(new Date('2021-05')); // => 31
 */
function getMonthDays(time) {
  if (isUdf(time)) time = new Date();
  var date = formatToDate(time);
  if (!date) return NaN;
  var year = date.getFullYear();
  var month = date.getMonth() + 1;
  return new Date(year, month, 0).getDate();
}

module.exports = getMonthDays;
