From 823248f02500b1a37b882270b2d8ca129dd61cef Mon Sep 17 00:00:00 2001 From: Hosteroid Date: Sun, 12 Oct 2025 11:02:34 +0300 Subject: [PATCH] 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. --- app/Services/TldRegistryService.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/Services/TldRegistryService.php b/app/Services/TldRegistryService.php index 13e86d7..a648336 100644 --- a/app/Services/TldRegistryService.php +++ b/app/Services/TldRegistryService.php @@ -1912,8 +1912,15 @@ class TldRegistryService } try { - // Create DateTime object (handles both ISO 8601 and MySQL datetime) - $dateTime = new \DateTime($date); + // 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); + } else { + // Plain datetime (from database) - explicitly parse as UTC + $dateTime = new \DateTime($date, new \DateTimeZone('UTC')); + } // Convert to UTC to ensure consistent comparison $dateTime->setTimezone(new \DateTimeZone('UTC'));