Enhance TimefixService to improve local time extraction from UTC timestamps, ensuring accurate conversion and consistent time representation across both corrected values and original worklog entries.

This commit is contained in:
Torsten Schulz (local)
2025-10-20 09:01:54 +02:00
parent 074c08ccd1
commit 3a4b0c48db

View File

@@ -62,10 +62,21 @@ class TimefixService {
// Verwende korrigierte Werte aus Timefix
const tf = timefixForEntry[0];
// WICHTIG: DB speichert UTC, Frontend erwartet lokale Zeit
if (typeof tf.fix_date_time === 'string') {
// Parse als UTC und konvertiere zu lokaler Zeit
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) {
// Date-Objekt: Verwende lokale Zeit
hours = tf.fix_date_time.getHours();
minutes = tf.fix_date_time.getMinutes();
}
@@ -73,12 +84,23 @@ class TimefixService {
action = tf.fix_type;
} else {
// Keine Korrektur - verwende Original-Werte aus Worklog
// WICHTIG: DB speichert UTC, Frontend erwartet lokale Zeit
if (typeof entry.tstamp === 'string') {
// Parse als UTC und konvertiere zu lokaler Zeit
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) {
hours = entry.tstamp.getUTCHours();
minutes = entry.tstamp.getUTCMinutes();
// Date-Objekt: Verwende lokale Zeit
hours = entry.tstamp.getHours();
minutes = entry.tstamp.getMinutes();
}
// Parse state