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

export function formatDate(startDate, endDate) {
  // If specific date is not defined yet. Meaning startDate is 2018-02 for instance
  if (startDate.length === 7) { return format(parse(`${startDate}-01`), 'MMMM'); }

  const parsedStartDate = parse(startDate);
  let date = format(parsedStartDate, 'MMM, Do');

  if (endDate && startDate !== endDate) {
    date += format(parse(endDate), '-Do');
  }

  return date;
}

export function generateEventJSONLD({name, url, city, country, startDate, endDate}) {
  const data = {
    '@context': 'http://schema.org',
    '@type': 'Event',
    location: {
      '@type': 'Place',
      address: {
        '@type': 'PostalAddress',
        addressLocality: city,
        addressCountry: country,
      },
      name: `${city}, ${country}`,
    },
    name,
    startDate,
    url,
    endDate: (endDate || startDate),
  };

  return JSON.stringify(data);
}

@@ -299,97 +299,91 @@
 e);%0A
+%0A
   
-let date = format(parsedStartDate, 'MMM, Do');%0A%0A  if (endDate && startDate !== 
+if (endDate && startDate !== endDate) %7B%0A    const parsedEndDate = parse(
 endDate)
  %7B%0A 
@@ -382,23 +382,61 @@
 ate)
- %7B
+;
 %0A    
-date += 
+return %60$%7Bformat(parsedStartDate, 'MMMM, D')%7D$%7B
 form
@@ -447,25 +447,24 @@
 arse
-(e
+dE
 ndDate
-)
 , '-Do')
 ;%0A  
@@ -463,29 +463,74 @@
 Do')
+%7D%60
 ;%0A  %7D
-%0A%0A  return date;
+ else %7B%0A    return format(parsedStartDate, 'MMMM, Do');%0A  %7D
 %0A%7D%0A%0A

Update formatDate helper