import spacetime from 'spacetime';

const clockContainers = document.querySelectorAll('.clock span');

const getTime = () => {
  const d = spacetime(new Date(), 'Europe/Zurich');
  return d.format('{hour-24-pad}:{minute-pad}:{second-pad}');
};

const setTime = () => {
  clockContainers.forEach(clock => clock.innerHTML = `<span class="time">${getTime()}</span> CEST`);
};

const clock = () => {
  if (clockContainers.length) {
    setTime();
    setInterval(setTime, 1000);
  }
};

export default clock;
