if DateTime::__construct() throws error for strings interpreted as Ymd, catch it and try again as timestamp

This commit is contained in:
Ralf Becker 2010-11-04 13:37:08 +00:00
parent b97ba82f27
commit 99f88b97f2

View File

@ -97,13 +97,21 @@ class egw_time extends DateTime
case 'string':
if (!(is_numeric($time) && ($time > 21000000 || $time < 19000000)))
{
if (is_numeric($time) && strlen($time) == 8) $time .= 'T000000'; // 'Ymd' string used in calendar to represent a date
$t_str = $time;
if (is_numeric($time) && strlen($time) == 8) $t_str .= 'T000000'; // 'Ymd' string used in calendar to represent a date
// $time ending in a Z (Zulu or UTC time), is unterstood by DateTime class itself
parent::__construct($time,$tz);
try {
parent::__construct($t_str,$tz);
break;
}
catch(Exception $e) {
// if string is nummeric, ignore the exception and treat string as timestamp
if (!is_numeric($time)) throw $e;
}
}
$type = 'integer';
// fall through for timestamps
case 'double': // 64bit integer (timestamps > 2038) are treated on 32bit systems as double
case 'integer':
/* ToDo: Check if PHP5.3 setTimestamp does the same, or always expects UTC timestamp
if (PHP_VERSION >= 5.3)