Refactor TimefixService to create a local Date object from input and convert it to a UTC string for database storage, ensuring accurate time representation.
This commit is contained in:
@@ -282,9 +282,21 @@ class TimefixService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Erstelle die korrigierte Zeit als Date-Objekt
|
// Erstelle die korrigierte Zeit als Date-Objekt
|
||||||
|
// WICHTIG: Frontend sendet lokale Zeit, DB erwartet UTC
|
||||||
const [newHours, newMinutes] = newTime.split(':').map(Number);
|
const [newHours, newMinutes] = newTime.split(':').map(Number);
|
||||||
const [newYear, newMonth, newDay] = newDate.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
|
// Prüfe ob bereits ein Timefix existiert
|
||||||
const existingTimefix = await Timefix.findOne({
|
const existingTimefix = await Timefix.findOne({
|
||||||
|
|||||||
Reference in New Issue
Block a user