"use strict"; async function fetchWithToken(url, options) { const authToken = localStorage.getItem('token'); return await fetch(url, {...options, headers: { 'Authorization': `Bearer ${authToken}`, 'Content-Type': 'application/json', }}); } // Function to format time as HH:MM function formatTime(date) { const hours = date.getUTCHours().toString().padStart(2, '0'); const minutes = date.getUTCMinutes().toString().padStart(2, '0'); return `${hours}:${minutes}`; } // Function to get the time span (e.g., 09:00 to 10:00) function getTimeSpan(start, end) { return `${formatTime(new Date(start))} to ${formatTime(new Date(end))}`; } async function parseOrRedirect(response) { if (response.status === 401) { window.location.replace("/html/auth.html"); return; } if (response.status === 410) { window.location.replace("/html/410.html"); return; } const js = await response.json(); if (!response.ok) { window.location.replace("/html/404.html"); } return js; } export { fetchWithToken, getTimeSpan, parseOrRedirect };