import { format, parse, parseISO } from 'date-fns';

export function convertStringToDate(dateString: string): Date {
   try {
      if (format(parse(dateString, 'yyyyMMddHHmmss', new Date()), 'yyyyMMddHHmmss') === dateString) {
         return parse(dateString, 'yyyyMMddHHmmss', new Date());
      }
   } catch (e) {}

   try {
      if (format(parse(dateString, 'yyyy/MM/dd', new Date()), 'yyyy/MM/dd') === dateString) {
         return parse(dateString, 'yyyy/MM/dd', new Date());
      }
   } catch (e) {}

   try {
      if (format(parse(dateString, 'yyyy-MM-dd', new Date()), 'yyyy-MM-dd') === dateString) {
         return parse(dateString, 'yyyy-MM-dd', new Date());
      }
   } catch (e) {}

   return parseISO(dateString);
}
