From b70e0fdf09506fcf53af951d64a3ae47309fa245 Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Thu, 31 Aug 2017 10:35:31 -0700 Subject: Add php support for Timestamp. (#3575) * Add php support for Timestamp. * Fix comments --- php/tests/well_known_test.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'php/tests') 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')); + } } -- cgit v1.2.3