diff --git a/components/modales/SettingsModal.jsx b/components/modales/SettingsModal.jsx index a3ef980..57858b1 100644 --- a/components/modales/SettingsModal.jsx +++ b/components/modales/SettingsModal.jsx @@ -131,40 +131,38 @@ function SettingModal({ showModal, onClose }) { const handleSetDateTime = () => { const currentDate = new Date(); - // Format date and time as required by the system: + // Format date and time as required by the system without leading zeros: const year = currentDate.getFullYear().toString().slice(-2); // Last two digits of the year - const month = String(currentDate.getMonth() + 1).padStart(2, "0"); // Month (1-12) - const day = String(currentDate.getDate()).padStart(2, "0"); // Day (1-31) + const month = Number(currentDate.getMonth() + 1); // Convert to Number to remove leading zero + const day = Number(currentDate.getDate()); // Convert to Number to remove leading zero - const hours = String(currentDate.getHours()).padStart(2, "0"); // Hours (0-23) - const minutes = String(currentDate.getMinutes()).padStart(2, "0"); // Minutes (0-59) - const seconds = String(currentDate.getSeconds()).padStart(2, "0"); // Seconds (0-59) + const hours = Number(currentDate.getHours()); // Convert to Number to remove leading zero + const minutes = Number(currentDate.getMinutes()); // Convert to Number to remove leading zero + const seconds = Number(currentDate.getSeconds()); // Convert to Number to remove leading zero - // Date command + // Date and Time commands const dateCommand = `CLK00=${year}-${month}-${day}`; - - // Time command const timeCommand = `CLK01=${hours}-${minutes}-${seconds}`; - // Log the URLs to the console - console.log(`/CPL?${dateCommand}`); - console.log(`/CPL?${timeCommand}`); + + // Get the current path and ensure it ends with ".html" + let currentPath = window.location.pathname; + if (!currentPath.endsWith(".html")) { + currentPath += ".html"; + } + + // Full URL with host, current path, date, and time commands + const url = `${window.location.origin}/CPL?${currentPath}&${dateCommand}&${timeCommand}`; + + // Log the full URL to the console + console.log(url); // Send the commands to the server using fetch and GET method - fetch(`/CPL?${dateCommand}`, { method: "GET" }) + fetch(url, { method: "GET" }) .then((response) => { if (response.ok) { - alert("Datum erfolgreich gesetzt!"); - return fetch(`/CPL?${timeCommand}`, { method: "GET" }); + alert("Datum und Uhrzeit erfolgreich gesetzt!"); } else { - alert("Fehler beim Setzen des Datums!"); - throw new Error("Date setting failed."); - } - }) - .then((response) => { - if (response.ok) { - alert("Uhrzeit erfolgreich gesetzt!"); - } else { - alert("Fehler beim Setzen der Uhrzeit!"); + alert("Fehler beim Setzen von Datum und Uhrzeit!"); } }) .catch((error) => { @@ -172,6 +170,7 @@ function SettingModal({ showModal, onClose }) { alert("Fehler beim Setzen von Datum und Uhrzeit!"); }); }; + //--------------------------------------------------- // Setze initiale Werte nur beim Öffnen des Modals useEffect(() => {