Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encoded DateTime incompatible with Decoder #29

Closed
jahudka opened this issue May 3, 2016 · 0 comments
Closed

Encoded DateTime incompatible with Decoder #29

jahudka opened this issue May 3, 2016 · 0 comments

Comments

@jahudka
Copy link

jahudka commented May 3, 2016

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..

dg added a commit that referenced this issue May 3, 2016
@dg dg closed this as completed in b43c4de May 3, 2016
dg added a commit that referenced this issue May 3, 2016
dg added a commit that referenced this issue May 17, 2016
dg added a commit that referenced this issue May 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant