Support DD/MM/YYYY WHOIS date parsing
Add handling for European-style dates (DD/MM/YYYY and DD/MM/YYYY HH:MM:SS) before calling strtotime. The code detects a leading DD/MM/YYYY pattern, interprets it as day/month/year when day>12 or when both day and month are <=12 (favoring European format used by many WHOIS servers like .pt, .es, .fr), then converts it to YYYY-MM-DD with any time part preserved. If month>12 the original string is left for strtotime to handle. This improves robust parsing of WHOIS date strings from servers that use day-first formats.
This commit is contained in:
@@ -1041,6 +1041,27 @@ class WhoisService
|
||||
$dateString = preg_replace('/^(before|after):/i', '', $dateString);
|
||||
$dateString = trim($dateString);
|
||||
|
||||
// Handle DD/MM/YYYY format (European format used by many WHOIS servers like .pt, .es, .fr, etc.)
|
||||
// Pattern: DD/MM/YYYY or DD/MM/YYYY HH:MM:SS
|
||||
if (preg_match('#^(\d{1,2})/(\d{1,2})/(\d{4})(.*)$#', $dateString, $matches)) {
|
||||
$day = (int)$matches[1];
|
||||
$month = (int)$matches[2];
|
||||
$year = (int)$matches[3];
|
||||
$timePart = trim($matches[4]);
|
||||
|
||||
// If day > 12, it's definitely DD/MM/YYYY format
|
||||
// If month > 12, it's definitely MM/DD/YYYY format (invalid day, so swap)
|
||||
// If both <= 12, assume DD/MM/YYYY (European format) as it's more common globally for WHOIS
|
||||
if ($day > 12 || ($day <= 12 && $month <= 12)) {
|
||||
// Treat as DD/MM/YYYY - convert to YYYY-MM-DD format
|
||||
$dateString = sprintf('%04d-%02d-%02d', $year, $month, $day);
|
||||
if (!empty($timePart)) {
|
||||
$dateString .= ' ' . $timePart;
|
||||
}
|
||||
}
|
||||
// If month > 12, strtotime will fail or we let it try MM/DD/YYYY naturally
|
||||
}
|
||||
|
||||
// Try to parse the date
|
||||
$timestamp = strtotime($dateString);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user