aboutsummaryrefslogtreecommitdiffhomepage
path: root/php/tests
diff options
context:
space:
mode:
authorGravatar Paul Yang <TeBoring@users.noreply.github.com>2017-08-31 10:35:31 -0700
committerGravatar GitHub <noreply@github.com>2017-08-31 10:35:31 -0700
commitb70e0fdf09506fcf53af951d64a3ae47309fa245 (patch)
tree5daf2049946d001b8868f3a8c6e94c2c9cb9acd3 /php/tests
parentc7457ef65a7a8584b1e3bd396c401ccf8e275ffa (diff)
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.php21
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'));
+ }
}