-
Notifications
You must be signed in to change notification settings - Fork 15.6k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[PHP] Merging of Timestamp field from JSON string results in wrong seconds #4335
Comments
For elaborating this issue, I want to clarify these.
Is this gonna be critical path? If so, we'd better to put enough test case on these related funcs. |
Are you using c extension? |
@TeBoring I didn't use the C ext. I used the PHP script ( |
Just in case you need it, you can find the test files as composer project on https://github.com/sbhalim/protobuf-issue-4335 |
@bitevo In your example, |
Can't reproduce. Maybe this has been fixed. |
Protobuf php lib encodes 123_000_000 nano like this: 2000-01-01T00:00:00.**123**Z but then it gets decoded into 123 nanoseconds instead of 123_000_000. There were issue opened some time ago that also describes this behaviour #4335 Closes #12396 COPYBARA_INTEGRATE_REVIEW=#12396 from kindratmakc:bugfix/inconsistent-timestamp-json-encode-decode df47c96 FUTURE_COPYBARA_INTEGRATE_REVIEW=#12396 from kindratmakc:bugfix/inconsistent-timestamp-json-encode-decode df47c96 PiperOrigin-RevId: 603110109
Protobuf php lib encodes 123_000_000 nano like this: 2000-01-01T00:00:00.**123**Z but then it gets decoded into 123 nanoseconds instead of 123_000_000. There were issue opened some time ago that also describes this behaviour #4335 Closes #12396 COPYBARA_INTEGRATE_REVIEW=#12396 from kindratmakc:bugfix/inconsistent-timestamp-json-encode-decode df47c96 FUTURE_COPYBARA_INTEGRATE_REVIEW=#12396 from kindratmakc:bugfix/inconsistent-timestamp-json-encode-decode df47c96 PiperOrigin-RevId: 603110109
Protobuf php lib encodes 123_000_000 nano like this: 2000-01-01T00:00:00.**123**Z but then it gets decoded into 123 nanoseconds instead of 123_000_000. There were issue opened some time ago that also describes this behaviour #4335 Closes #12396 COPYBARA_INTEGRATE_REVIEW=#12396 from kindratmakc:bugfix/inconsistent-timestamp-json-encode-decode df47c96 PiperOrigin-RevId: 603118615
Protobuf php lib encodes 123_000_000 nano like this: 2000-01-01T00:00:00.**123**Z but then it gets decoded into 123 nanoseconds instead of 123_000_000. There were issue opened some time ago that also describes this behaviour #4335 Closes #12396 COPYBARA_INTEGRATE_REVIEW=#12396 from kindratmakc:bugfix/inconsistent-timestamp-json-encode-decode df47c96 PiperOrigin-RevId: 603118615
Protobuf php lib encodes 123_000_000 nano like this: 2000-01-01T00:00:00.**123**Z but then it gets decoded into 123 nanoseconds instead of 123_000_000. There were issue opened some time ago that also describes this behaviour #4335 Closes #12396 COPYBARA_INTEGRATE_REVIEW=#12396 from kindratmakc:bugfix/inconsistent-timestamp-json-encode-decode df47c96 PiperOrigin-RevId: 603118615 Co-authored-by: kindratmakc <kindratmakc@gmail.com>
Protobuf php lib encodes 123_000_000 nano like this: 2000-01-01T00:00:00.**123**Z but then it gets decoded into 123 nanoseconds instead of 123_000_000. There were issue opened some time ago that also describes this behaviour protocolbuffers#4335 Closes protocolbuffers#12396 COPYBARA_INTEGRATE_REVIEW=protocolbuffers#12396 from kindratmakc:bugfix/inconsistent-timestamp-json-encode-decode df47c96 PiperOrigin-RevId: 603118615
Merging of Timestamp field from JSON string results in wrong seconds. In my test, it was off by 1 sec for microsecond resolution string and even worse for nanosecond resolution string.
Test output (run on MacOS High Sierra):
The issue described here is about correctness, not precision. I know PHP doesn't natively support nano second, but string parsing should not be affected by that. There will be lost of precision during conversion from string to PHP
DateTime
object, but the number of seconds should be always correct.The proto file I used in the test:
PHP test script (using compiled PHP class):
The text was updated successfully, but these errors were encountered: