diff options
Diffstat (limited to 'php/tests/well_known_test.php')
-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')); + } } |