From 3ce170236740a9a5b8334a9dff4936a9044881f3 Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Wed, 15 Apr 2026 11:33:24 +0200 Subject: [PATCH] fix(AutoFetchMatchResultsService): improve date parsing with timezone handling - Enhanced date parsing logic to handle ISO strings with explicit timezones, converting them to local time before persisting. - Added normalization and validation checks to ensure accurate date and time extraction from input strings. - Improved robustness of the date handling functionality, ensuring better compatibility with various date formats. --- .../services/autoFetchMatchResultsService.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/backend/services/autoFetchMatchResultsService.js b/backend/services/autoFetchMatchResultsService.js index 209b092d..c6d8e0e6 100644 --- a/backend/services/autoFetchMatchResultsService.js +++ b/backend/services/autoFetchMatchResultsService.js @@ -20,7 +20,22 @@ class AutoFetchMatchResultsService { } if (typeof rawValue === 'string') { - const match = rawValue.match(/^(\d{4})-(\d{2})-(\d{2})(?:[T\s](\d{2}):(\d{2})(?::(\d{2}))?)?/); + const normalized = rawValue.trim(); + const hasExplicitTimezone = /(?:Z|[+-]\d{2}:?\d{2})$/i.test(normalized); + + // ISO values with explicit timezone are often UTC timestamps. + // Convert them to local clock time before persisting date/time parts. + if (hasExplicitTimezone) { + const zoned = new Date(normalized); + if (!Number.isNaN(zoned.getTime())) { + return { + date: new Date(zoned.getFullYear(), zoned.getMonth(), zoned.getDate(), 0, 0, 0, 0), + time: `${String(zoned.getHours()).padStart(2, '0')}:${String(zoned.getMinutes()).padStart(2, '0')}:${String(zoned.getSeconds()).padStart(2, '0')}` + }; + } + } + + const match = normalized.match(/^(\d{4})-(\d{2})-(\d{2})(?:[T\s](\d{2}):(\d{2})(?::(\d{2}))?)?/); if (match) { const [, year, month, day, hour = '00', minute = '00', second = '00'] = match; return {