function parseDate(date) {
  var newDate = date;

  if (newDate === null) {
    return null;
  }

  if (!(newDate instanceof Date)) {
    newDate = new Date(newDate);

    if (newDate.toString() === 'Invalid Date') {
      return null;
    }
  }

  return newDate;
}
Parse the provided date and check if it's valid.

@param {String|Date} date Date string or object.
@returns {Date|null} Parsed Date object or null, if not a valid date string.