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

DateTime and DateTimeImmutable from PHP 7.1 serialization and deserialization with microseconds #1033

Closed
pdec86 opened this issue Jan 16, 2019 · 2 comments

Comments

@pdec86
Copy link

pdec86 commented Jan 16, 2019

Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no

According to PHP documentation, DateTime::setTime
Version | Description
7.1.0 | The microseconds parameter was added.

Steps required to reproduce the problem

Code like follows fails:
$date = new \DateTimeImmutable(null);
$serializer = SerializerBuilder::create()->build();
$json = $serializer->serialize($date, 'json');
$dateBack = $serializer->deserialize($json, \DateTimeImmutable::class, 'json');
$this->assertEquals($date, $dateBack);

Expected Result

Tests pass OK.

Actual Result

Failed asserting that two DateTime objects are equal.
--- Expected
+++ Actual
@@ @@
-2019-01-16T18:45:54.578422+0100
+2019-01-16T18:45:54.000000+0100

@goetas
Copy link
Collaborator

goetas commented Jan 16, 2019

Not sure if your test makes sense. this two dates will be always different unless you serialize also the microsecods

@pdec86
Copy link
Author

pdec86 commented Jan 16, 2019

Yes, I thought that full DateTime object will be serialized, also with microseconds if they are part of the DateTime object. But maybe they should not be serialized because of some reasons in JMS serializer.

In one of my projects, I store DateTimeImmutable of an object, of an event which has occurred in the system.

If new PHP version supports microseconds it would be beneficial to me if serialized time would contain those microseconds, so it is less possible, that two events occur on the same time - with same hour, minute, second and microseconds.

If it's not a bug, please close that issue. I will refactor my tests so microseconds won't be considered if two DateTimeImmutable are equal.

@goetas goetas closed this as completed Jan 16, 2019
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

2 participants