-
-
Notifications
You must be signed in to change notification settings - Fork 36
Description
DateTime representation in generated Neon isn't properly parsed as a DateTime-compatible string and is therefore decoded as a string instead of a DateTime instance.
This breaks stuff, as $data !== decode(encode($data)).
PHP 7.0.3 CLI from MacPorts.
$data = [
'myDate' => new DateTime('2016-06-03T19:00:00+02:00'),
];
$neon = Nette\Neon\Neon::encode($data, Nette\Neon\Neon::BLOCK);
$decoded = Nette\Neon\Neon::decode($neon);
// Fatal error: Call to a member function format() on a string
$decoded['myDate']->format('Y-m-d H:i:s O');The problem is that the encoder formats a DateTime using the Y-m-d H:i:s O format string; the O format character doesn't add a colon between the timezone offset's hours and minutes (unlike the P format character). The regular expression in the decoder won't match the string without the colon in the timezone offset (the specific part of the regexp in question being Z|[-+]\d\d?(?::\d\d)?).
Fixing this is as simple as putting a single question mark in the decoder regexp after the offending colon, making it Z|[-+]\d\d?(?::?\d\d)?. I'd fix this and send a PR, but I won't get around to doing it today..