var_dump(date_default_timezone_get()); $date = new \DateTimeImmutable('1960-01-01 12:12:12.1'); var_dump($date); $bsonDate = new \MongoDB\BSON\UTCDateTime($date); var_dump($bsonDate); $newDate = $bsonDate->toDateTime(); var_dump($newDate); var_dump($newDate->format('Y-m-d H:i:s.u')); \Carbon\Carbon::instance($newDate);
The last line generates an error while it should create a Carbon object with the correct date object.
Output:
string(3) "UTC" object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "1960-01-01 12:12:12.100000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } object(MongoDB\BSON\UTCDateTime)#6 (1) { ["milliseconds"]=> string(13) "-315575267900" } object(DateTime)#7 (3) { ["date"]=> string(27) "1960-01-01 12:12:13.-900000" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } string(27) "1960-01-01 12:12:13.-900000" PHP Fatal error: Uncaught DateMalformedStringException: Failed to parse time string (1960-01-01 12:12:13.-900000) at position 24 (0): Unexpected character in vendor/nesbot/carbon/src/Carbon/Traits/Creator.php:100 Stack trace: #0 vendor/nesbot/carbon/src/Carbon/Traits/Creator.php(100): DateTime->__construct('1960-01-01 12:1...', Object(Carbon\CarbonTimeZone)) #1 vendor/nesbot/carbon/src/Carbon/Traits/Creator.php(149): Carbon\Carbon->__construct('1960-01-01 12:1...', Object(Carbon\CarbonTimeZone)) #2 date.php(14): Carbon\Carbon::instance(Object(DateTime)) #3 {main}Next Carbon\Exceptions\InvalidFormatException: Failed to parse time string (1960-01-01 12:12:13.-900000) at position 24 (0): Unexpected character in vendor/nesbot/carbon/src/Carbon/Traits/Creator.php:102 Stack trace: #0 vendor/nesbot/carbon/src/Carbon/Traits/Creator.php(149): Carbon\Carbon->__construct('1960-01-01 12:1...', Object(Carbon\CarbonTimeZone)) #1 date.php(14): Carbon\Carbon::instance(Object(DateTime)) #2 {main} thrown in vendor/nesbot/carbon/src/Carbon/Traits/Creator.php on line 102
Issue found while working on tests for PHPORM-234