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({