File tree Expand file tree Collapse file tree
src/Google/Protobuf/Internal Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -485,6 +485,10 @@ public static function parseTimestamp($timestamp)
485485 $ nanoseconds = substr ($ timestamp , $ periodIndex + 1 , $ nanosecondsLength );
486486 $ nanoseconds = intval ($ nanoseconds );
487487
488+ if ($ nanosecondsLength < 9 ) {
489+ $ nanoseconds = $ nanoseconds * pow (10 , 9 - $ nanosecondsLength );
490+ }
491+
488492 // remove the nanoseconds and preceding period from the timestamp
489493 $ date = substr ($ timestamp , 0 , $ periodIndex );
490494 $ timezone = substr ($ timestamp , $ periodIndex + $ nanosecondsLength + 1 );
Original file line number Diff line number Diff line change @@ -992,6 +992,16 @@ public function testEncodeTimestamp()
992992 $ m ->serializeToJsonString ());
993993 }
994994
995+ public function testEncodeDecodeTimestampConsistency ()
996+ {
997+ $ m = new Google \Protobuf \Timestamp ();
998+ $ m ->setSeconds (946684800 );
999+ $ m ->setNanos (123000000 );
1000+ $ m ->mergeFromJsonString ($ m ->serializeToJsonString ());
1001+ $ this ->assertEquals (946684800 , $ m ->getSeconds ());
1002+ $ this ->assertEquals (123000000 , $ m ->getNanos ());
1003+ }
1004+
9951005 public function testDecodeTopLevelValue ()
9961006 {
9971007 $ m = new Value ();
You can’t perform that action at this time.
0 commit comments