Enhance TimefixService to correctly handle UTC to local time conversion for date and timestamp values; ensure consistent time representation across the application.

This commit is contained in:
Torsten Schulz (local)
2025-10-20 08:52:11 +02:00
parent 52712db78d
commit 2c7a34e50c

View File

@@ -62,10 +62,21 @@ class TimefixService {
// Verwende korrigierte Werte aus Timefix // Verwende korrigierte Werte aus Timefix
const tf = timefixForEntry[0]; const tf = timefixForEntry[0];
// WICHTIG: DB speichert UTC, Frontend erwartet lokale Zeit
if (typeof tf.fix_date_time === 'string') { if (typeof tf.fix_date_time === 'string') {
// Parse als UTC und konvertiere zu lokaler Zeit
const [datePart, timePart] = tf.fix_date_time.split(' '); const [datePart, timePart] = tf.fix_date_time.split(' ');
[hours, minutes] = timePart.split(':').map(Number); const [h, m, s] = timePart.split(':').map(Number);
// Erstelle UTC-Date aus den Komponenten
const [year, month, day] = datePart.split('-').map(Number);
const utcDate = new Date(Date.UTC(year, month - 1, day, h, m, s));
// Extrahiere lokale Stunden/Minuten
hours = utcDate.getHours();
minutes = utcDate.getMinutes();
} else if (tf.fix_date_time instanceof Date) { } else if (tf.fix_date_time instanceof Date) {
// Date-Objekt: Verwende lokale Zeit
hours = tf.fix_date_time.getHours(); hours = tf.fix_date_time.getHours();
minutes = tf.fix_date_time.getMinutes(); minutes = tf.fix_date_time.getMinutes();
} }
@@ -73,12 +84,23 @@ class TimefixService {
action = tf.fix_type; action = tf.fix_type;
} else { } else {
// Keine Korrektur - verwende Original-Werte aus Worklog // Keine Korrektur - verwende Original-Werte aus Worklog
// WICHTIG: DB speichert UTC, Frontend erwartet lokale Zeit
if (typeof entry.tstamp === 'string') { if (typeof entry.tstamp === 'string') {
// Parse als UTC und konvertiere zu lokaler Zeit
const [datePart, timePart] = entry.tstamp.split(' '); const [datePart, timePart] = entry.tstamp.split(' ');
[hours, minutes] = timePart.split(':').map(Number); const [h, m, s] = timePart.split(':').map(Number);
// Erstelle UTC-Date aus den Komponenten
const [year, month, day] = datePart.split('-').map(Number);
const utcDate = new Date(Date.UTC(year, month - 1, day, h, m, s));
// Extrahiere lokale Stunden/Minuten
hours = utcDate.getHours();
minutes = utcDate.getMinutes();
} else if (entry.tstamp instanceof Date) { } else if (entry.tstamp instanceof Date) {
hours = entry.tstamp.getUTCHours(); // Date-Objekt: Verwende lokale Zeit
minutes = entry.tstamp.getUTCMinutes(); hours = entry.tstamp.getHours();
minutes = entry.tstamp.getMinutes();
} }
// Parse state // Parse state