diff options
author | Paul Yang <TeBoring@users.noreply.github.com> | 2017-08-31 10:35:31 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-31 10:35:31 -0700 |
commit | b70e0fdf09506fcf53af951d64a3ae47309fa245 (patch) | |
tree | 5daf2049946d001b8868f3a8c6e94c2c9cb9acd3 /php/tests | |
parent | c7457ef65a7a8584b1e3bd396c401ccf8e275ffa (diff) | |
download | protobuf-b70e0fdf09506fcf53af951d64a3ae47309fa245.tar.gz protobuf-b70e0fdf09506fcf53af951d64a3ae47309fa245.tar.bz2 protobuf-b70e0fdf09506fcf53af951d64a3ae47309fa245.zip |
Add php support for Timestamp. (#3575)
* Add php support for Timestamp.
* Fix comments
Diffstat (limited to 'php/tests')
-rw-r--r-- | php/tests/well_known_test.php | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/php/tests/well_known_test.php b/php/tests/well_known_test.php index bdf41bfb..4441b13b 100644 --- a/php/tests/well_known_test.php +++ b/php/tests/well_known_test.php @@ -5,6 +5,7 @@ require_once('test_util.php'); use Google\Protobuf\GPBEmpty; use Google\Protobuf\Any; +use Google\Protobuf\Timestamp; use Foo\TestMessage; @@ -86,4 +87,24 @@ class WellKnownTest extends TestBase { $any->setValue("abc"); $any->unpack(); } + + public function testTimestamp() + { + $timestamp = new Timestamp(); + + $timestamp->setSeconds(1); + $timestamp->setNanos(2); + $this->assertEquals(1, $timestamp->getSeconds()); + $this->assertSame(2, $timestamp->getNanos()); + + date_default_timezone_set('UTC'); + $from = new DateTime('2011-01-01T15:03:01.012345UTC'); + $timestamp->fromDateTime($from); + $this->assertEquals($from->format('U'), $timestamp->getSeconds()); + $this->assertSame(0, $timestamp->getNanos()); + + $to = $timestamp->toDateTime(); + $this->assertSame(\DateTime::class, get_class($to)); + $this->assertSame($from->format('U'), $to->format('U')); + } } |