From 12a83cd7ec27ec64f1b373a7ec0997297ae5dcb8 Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Mon, 20 Oct 2025 08:53:14 +0200 Subject: [PATCH] Refactor TimefixService to create a local Date object from input and convert it to a UTC string for database storage, ensuring accurate time representation. --- backend/src/services/TimefixService.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/backend/src/services/TimefixService.js b/backend/src/services/TimefixService.js index 4216dcc..106cc81 100644 --- a/backend/src/services/TimefixService.js +++ b/backend/src/services/TimefixService.js @@ -282,9 +282,21 @@ class TimefixService { } // Erstelle die korrigierte Zeit als Date-Objekt + // WICHTIG: Frontend sendet lokale Zeit, DB erwartet UTC const [newHours, newMinutes] = newTime.split(':').map(Number); const [newYear, newMonth, newDay] = newDate.split('-').map(Number); - const correctedDateTime = new Date(newYear, newMonth - 1, newDay, newHours, newMinutes, 0); + + // Erstelle lokales Date-Objekt + const localDateTime = new Date(newYear, newMonth - 1, newDay, newHours, newMinutes, 0); + + // Konvertiere zu UTC-String für die Datenbank (Format: YYYY-MM-DD HH:MM:SS) + const utcYear = localDateTime.getUTCFullYear(); + const utcMonth = String(localDateTime.getUTCMonth() + 1).padStart(2, '0'); + const utcDay = String(localDateTime.getUTCDate()).padStart(2, '0'); + const utcHours = String(localDateTime.getUTCHours()).padStart(2, '0'); + const utcMinutes = String(localDateTime.getUTCMinutes()).padStart(2, '0'); + const utcSeconds = String(localDateTime.getUTCSeconds()).padStart(2, '0'); + const correctedDateTime = `${utcYear}-${utcMonth}-${utcDay} ${utcHours}:${utcMinutes}:${utcSeconds}`; // Prüfe ob bereits ein Timefix existiert const existingTimefix = await Timefix.findOne({