Improve date parsing to handle timezones correctly

Updated date parsing logic to distinguish between ISO 8601 dates with timezone information and plain database datetimes. Plain datetimes are now explicitly parsed as UTC to ensure consistent handling and comparison.
This commit is contained in:
Hosteroid
2025-10-12 11:02:34 +03:00
parent 26ad852451
commit 823248f025

View File

@@ -1912,8 +1912,15 @@ class TldRegistryService
} }
try { try {
// Create DateTime object (handles both ISO 8601 and MySQL datetime) // If date has timezone info (ISO 8601 with Z or +00:00), parse it correctly
// Otherwise assume it's UTC (for dates from database)
if (strpos($date, 'T') !== false || strpos($date, 'Z') !== false || strpos($date, '+') !== false) {
// ISO 8601 format with timezone - parse as-is
$dateTime = new \DateTime($date); $dateTime = new \DateTime($date);
} else {
// Plain datetime (from database) - explicitly parse as UTC
$dateTime = new \DateTime($date, new \DateTimeZone('UTC'));
}
// Convert to UTC to ensure consistent comparison // Convert to UTC to ensure consistent comparison
$dateTime->setTimezone(new \DateTimeZone('UTC')); $dateTime->setTimezone(new \DateTimeZone('UTC'));