Fix #48: Fehlerbehandlung für Legacy-Datumsformat in stringToInstant()
Fehler: stringToInstant() in SqliteDocumentRecordRepositoryAdapter verwendete nur Instant.parse(), das nur ISO-8601 versteht. Ältere DB-Einträge haben aber das Format 'yyyy-MM-dd HH:mm:ss' (Leerzeichen statt T, kein Z). Lösung: Fallback-Logik implementiert 1. Versuch: Instant.parse() für ISO-8601 Format 2. Fallback: DateTimeFormatter für 'yyyy-MM-dd HH:mm:ss' → als UTC parsen Die Methode bleibt robust und gibt null zurück, wenn beide Parser fehlschlagen. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
+31
-4
@@ -6,6 +6,9 @@ import java.sql.PreparedStatement;
|
|||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
@@ -286,13 +289,37 @@ public class SqliteDocumentRecordRepositoryAdapter implements DocumentRecordRepo
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a string representation back to an Instant.
|
* Konvertiert eine String-Darstellung zurück zu einem Instant.
|
||||||
|
* <p>
|
||||||
|
* Unterstützt zwei Datumsformate für Rückwärtskompatibilität:
|
||||||
|
* <ul>
|
||||||
|
* <li>ISO-8601 (neu): "2026-04-27T11:32:25Z"</li>
|
||||||
|
* <li>Legacy-Format (älter): "2026-04-27 11:32:25" (wird als UTC interpretiert)</li>
|
||||||
|
* </ul>
|
||||||
*
|
*
|
||||||
* @param stringValue the ISO-8601 string representation, may be null
|
* @param stringValue die String-Darstellung des Datums, kann null sein
|
||||||
* @return the parsed Instant, or null if stringValue is null or blank
|
* @return das geparste Instant, oder null wenn stringValue null oder leer ist
|
||||||
*/
|
*/
|
||||||
private Instant stringToInstant(String stringValue) {
|
private Instant stringToInstant(String stringValue) {
|
||||||
return stringValue != null && !stringValue.isBlank() ? Instant.parse(stringValue) : null;
|
if (stringValue == null || stringValue.isBlank()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Versuch mit ISO-8601 Format (moderner Standard)
|
||||||
|
try {
|
||||||
|
return Instant.parse(stringValue);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Fallback auf älteres Format "yyyy-MM-dd HH:mm:ss" (als UTC)
|
||||||
|
try {
|
||||||
|
LocalDateTime dateTime = LocalDateTime.parse(stringValue,
|
||||||
|
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||||
|
return dateTime.atZone(ZoneId.of("UTC")).toInstant();
|
||||||
|
} catch (Exception fallbackException) {
|
||||||
|
logger.warn("Fehler beim Parsen der Instant-String '{}' in beiden Formaten (ISO-8601 und Legacy-Format)",
|
||||||
|
stringValue, fallbackException);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user