function parseEventTimes() {
  const dateformatter = Intl.DateTimeFormat(
    "en-CA",
    {
      hour: '2-digit',
      minute: '2-digit',
      timeZoneName: 'short',
      hour12: false
    });

  const eventtimes = document.getElementsByClassName("eventtime");
  for(eventtime of eventtimes) {
    const eventdate = eventtime.getAttribute("data-event-date")
    if(eventdate) {
      let parts = eventdate.split("-");
      if(parts.length !== 3)
        continue;

      const year = parseInt(parts[0], 10);
      const month = parseInt(parts[1], 10);
      const day = parseInt(parts[2], 10);

      parts = eventtime.innerText.split("UTC");
      if(parts.length < 2)
        continue;

      parts = parts[0].split(":")
      if(parts.length !== 2)
        continue;

      const hour = parseInt(parts[0], 10);
      const minute = parseInt(parts[1], 10);

      let date = Date.UTC(year, month, day, hour, minute);
      date = new Date(date);
      date = dateformatter.format(date);
      eventtime.innerHTML += " (" + date + ")";
    }
  }
}

function parseEventDates() {
  const dateformatter = Intl.DateTimeFormat(
    "en-CA",
    {
      weekday: 'short',
      hour: '2-digit',
      minute: '2-digit',
      timeZoneName: 'short',
      hour12: false
    });

  const eventdates = document.getElementsByClassName("eventdate");
  for(eventdate of eventdates) {
    const date_attribute = eventdate.getAttribute("data-event-datetime")
    if(date_attribute) {
      let date = Date.parse(date_attribute.replace("UTC", "Z"))
      if(isNaN(date))
        continue;

      date = new Date(date);
      date = dateformatter.format(date);
      eventdate.innerHTML += " (" + date + ")";
    }
  }}

document.addEventListener("DOMContentLoaded", (event) => {
  parseEventTimes();
  parseEventDates();
});
