export const formatDatetime = dateString => {
  const locale = navigator.language ? navigator.language : 'en-US';
  const dateOptions = {
    year: 'numeric',
    month: 'numeric',
    day: 'numeric',
    minute: 'numeric',
    hour: 'numeric',
  };

  const date = new Date(dateString);

  return date.toLocaleDateString(locale, dateOptions);
};

export const objectsFromArray = (array, key) => {
  const arrayEntries = array
    .filter(object => key in object)
    .map(object => {
      return [object[key], { ...object }];
    });

  return Object.fromEntries(arrayEntries);
};
