2010-12-13 01:17:16 +08:00
|
|
|
--TEST--
|
|
|
|
Bug #51866 (Lenient parsing with parseFromFormat)
|
|
|
|
--FILE--
|
|
|
|
<?php
|
2011-05-12 14:51:46 +08:00
|
|
|
date_default_timezone_set('UTC');
|
|
|
|
|
2010-12-13 01:17:16 +08:00
|
|
|
$tests = array(
|
|
|
|
array( 'Y-m-d', '2001-11-29 13:20:01' ),
|
|
|
|
array( 'Y-m-d+', '2001-11-29 13:20:01' ),
|
|
|
|
array( 'Y-m-d +', '2001-11-29 13:20:01' ),
|
|
|
|
array( 'Y-m-d+', '2001-11-29' ),
|
|
|
|
array( 'Y-m-d +', '2001-11-29' ),
|
|
|
|
array( 'Y-m-d +', '2001-11-29 ' ),
|
|
|
|
);
|
|
|
|
foreach( $tests as $test )
|
|
|
|
{
|
|
|
|
list($format, $str) = $test;
|
|
|
|
var_dump($format, $str);
|
|
|
|
$d = DateTime::createFromFormat($format, $str);
|
|
|
|
var_dump($d);
|
|
|
|
var_dump(DateTime::getLastErrors());
|
|
|
|
|
|
|
|
echo "\n\n";
|
|
|
|
}
|
|
|
|
--EXPECTF--
|
|
|
|
string(5) "Y-m-d"
|
|
|
|
string(19) "2001-11-29 13:20:01"
|
|
|
|
bool(false)
|
|
|
|
array(4) {
|
|
|
|
["warning_count"]=>
|
|
|
|
int(0)
|
|
|
|
["warnings"]=>
|
|
|
|
array(0) {
|
|
|
|
}
|
|
|
|
["error_count"]=>
|
|
|
|
int(1)
|
|
|
|
["errors"]=>
|
|
|
|
array(1) {
|
|
|
|
[10]=>
|
|
|
|
string(13) "Trailing data"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string(6) "Y-m-d+"
|
|
|
|
string(19) "2001-11-29 13:20:01"
|
2014-03-21 19:32:02 +08:00
|
|
|
object(DateTime)#%d (3) {
|
2010-12-13 01:17:16 +08:00
|
|
|
["date"]=>
|
2014-05-22 03:55:09 +08:00
|
|
|
string(26) "2001-11-29 %d:%d:%d.%d"
|
2010-12-13 01:17:16 +08:00
|
|
|
["timezone_type"]=>
|
|
|
|
int(3)
|
|
|
|
["timezone"]=>
|
2010-12-13 06:38:05 +08:00
|
|
|
string(%d) "%s"
|
2010-12-13 01:17:16 +08:00
|
|
|
}
|
|
|
|
array(4) {
|
|
|
|
["warning_count"]=>
|
|
|
|
int(1)
|
|
|
|
["warnings"]=>
|
|
|
|
array(1) {
|
|
|
|
[10]=>
|
|
|
|
string(13) "Trailing data"
|
|
|
|
}
|
|
|
|
["error_count"]=>
|
|
|
|
int(0)
|
|
|
|
["errors"]=>
|
|
|
|
array(0) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string(7) "Y-m-d +"
|
|
|
|
string(19) "2001-11-29 13:20:01"
|
2014-03-21 19:32:02 +08:00
|
|
|
object(DateTime)#%d (3) {
|
2010-12-13 01:17:16 +08:00
|
|
|
["date"]=>
|
2014-05-22 03:55:09 +08:00
|
|
|
string(26) "2001-11-29 %d:%d:%d.%d"
|
2010-12-13 01:17:16 +08:00
|
|
|
["timezone_type"]=>
|
|
|
|
int(3)
|
|
|
|
["timezone"]=>
|
2010-12-13 06:38:05 +08:00
|
|
|
string(%d) "%s"
|
2010-12-13 01:17:16 +08:00
|
|
|
}
|
|
|
|
array(4) {
|
|
|
|
["warning_count"]=>
|
|
|
|
int(1)
|
|
|
|
["warnings"]=>
|
|
|
|
array(1) {
|
|
|
|
[11]=>
|
|
|
|
string(13) "Trailing data"
|
|
|
|
}
|
|
|
|
["error_count"]=>
|
|
|
|
int(0)
|
|
|
|
["errors"]=>
|
|
|
|
array(0) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string(6) "Y-m-d+"
|
|
|
|
string(10) "2001-11-29"
|
2014-03-21 19:32:02 +08:00
|
|
|
object(DateTime)#%d (3) {
|
2010-12-13 01:17:16 +08:00
|
|
|
["date"]=>
|
2014-05-22 03:55:09 +08:00
|
|
|
string(26) "2001-11-29 %d:%d:%d.%d"
|
2010-12-13 01:17:16 +08:00
|
|
|
["timezone_type"]=>
|
|
|
|
int(3)
|
|
|
|
["timezone"]=>
|
2010-12-13 06:38:05 +08:00
|
|
|
string(%d) "%s"
|
2010-12-13 01:17:16 +08:00
|
|
|
}
|
|
|
|
array(4) {
|
|
|
|
["warning_count"]=>
|
|
|
|
int(0)
|
|
|
|
["warnings"]=>
|
|
|
|
array(0) {
|
|
|
|
}
|
|
|
|
["error_count"]=>
|
|
|
|
int(0)
|
|
|
|
["errors"]=>
|
|
|
|
array(0) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string(7) "Y-m-d +"
|
|
|
|
string(10) "2001-11-29"
|
|
|
|
bool(false)
|
|
|
|
array(4) {
|
|
|
|
["warning_count"]=>
|
|
|
|
int(0)
|
|
|
|
["warnings"]=>
|
|
|
|
array(0) {
|
|
|
|
}
|
|
|
|
["error_count"]=>
|
|
|
|
int(1)
|
|
|
|
["errors"]=>
|
|
|
|
array(1) {
|
|
|
|
[10]=>
|
|
|
|
string(12) "Data missing"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string(7) "Y-m-d +"
|
|
|
|
string(11) "2001-11-29 "
|
2014-03-21 19:32:02 +08:00
|
|
|
object(DateTime)#%d (3) {
|
2010-12-13 01:17:16 +08:00
|
|
|
["date"]=>
|
2014-05-22 03:55:09 +08:00
|
|
|
string(26) "2001-11-29 %d:%d:%d.%d"
|
2010-12-13 01:17:16 +08:00
|
|
|
["timezone_type"]=>
|
|
|
|
int(3)
|
|
|
|
["timezone"]=>
|
2010-12-13 06:38:05 +08:00
|
|
|
string(%d) "%s"
|
2010-12-13 01:17:16 +08:00
|
|
|
}
|
|
|
|
array(4) {
|
|
|
|
["warning_count"]=>
|
|
|
|
int(0)
|
|
|
|
["warnings"]=>
|
|
|
|
array(0) {
|
|
|
|
}
|
|
|
|
["error_count"]=>
|
|
|
|
int(0)
|
|
|
|
["errors"]=>
|
|
|
|
array(0) {
|
|
|
|
}
|
|
|
|
}
|