fix(AutoFetchMatchResultsService): improve date parsing with timezone handling
All checks were successful
Deploy tt-tagebuch / deploy (push) Successful in 36s

- 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.
This commit is contained in:
Torsten Schulz (local)
2026-04-15 11:33:24 +02:00
parent 58012e0a44
commit 3ce1702367

View File

@@ -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 {