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 {