// polyfill for safari Date API (which doesn't accept "YYYY-MM-DD" string as value)
export const newDate = (date, isUtcTime) => {
  if (typeof date === 'number') {
    return new Date(date);
  }
  if (typeof date === 'string') {
    const d = new Date(date.replace(/-/g, '/'));
    if (isUtcTime) {
      return new Date(
        Date.UTC(
          d.getFullYear(),
          d.getMonth(),
          d.getDate(),
          d.getHours(),
          d.getMinutes(),
          d.getSeconds(),
          d.getMilliseconds()
        )
      );
    }
    return new Date(d);
  }
  return new Date();
};
