'use strict';

/**
 * 格式化时间参数为日期对象
 * @param {Date|number|string} time
 * @returns {Date}
 *
 * formatToDate(new Date);      // => Date
 * formatToDate('2021-10');     // => Date
 * formatToDate(1636222480480); // => Date
 */
function formatToDate(time) {
  var date = time instanceof Date ? time : new Date(time);
  var dateTime = date.getTime();
  if (!dateTime && dateTime !== 0) return null;
  return date;
}

module.exports = formatToDate;
