aboutsummaryrefslogtreecommitdiffhomepage
path: root/php/src/Google/Protobuf/Timestamp.php
diff options
context:
space:
mode:
Diffstat (limited to 'php/src/Google/Protobuf/Timestamp.php')
-rw-r--r--php/src/Google/Protobuf/Timestamp.php41
1 files changed, 28 insertions, 13 deletions
diff --git a/php/src/Google/Protobuf/Timestamp.php b/php/src/Google/Protobuf/Timestamp.php
index 7da8e956..a793c7e3 100644
--- a/php/src/Google/Protobuf/Timestamp.php
+++ b/php/src/Google/Protobuf/Timestamp.php
@@ -55,7 +55,9 @@ use Google\Protobuf\Internal\GPBUtil;
* {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional
* seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution),
* are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone
- * is required, though only UTC (as indicated by "Z") is presently supported.
+ * is required. A proto3 JSON serializer should always use UTC (as indicated by
+ * "Z") when printing the Timestamp type and a proto3 JSON parser should be
+ * able to accept both UTC and other timezones (as indicated by an offset).
* For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past
* 01:30 UTC on January 15, 2017.
* In JavaScript, one can convert a Date object to this format using the
@@ -64,8 +66,8 @@ use Google\Protobuf\Internal\GPBUtil;
* to this format using [`strftime`](https://docs.python.org/2/library/time.html#time.strftime)
* with the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one
* can use the Joda Time's [`ISODateTimeFormat.dateTime()`](
- * http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime--)
- * to obtain a formatter capable of generating timestamps in this format.
+ * http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime--
+ * ) to obtain a formatter capable of generating timestamps in this format.
*
* Generated from protobuf message <code>google.protobuf.Timestamp</code>
*/
@@ -89,9 +91,26 @@ class Timestamp extends \Google\Protobuf\Internal\Message
*/
private $nanos = 0;
- public function __construct() {
+ /**
+ * Constructor.
+ *
+ * @param array $data {
+ * Optional. Data for populating the Message object.
+ *
+ * @type int|string $seconds
+ * Represents seconds of UTC time since Unix epoch
+ * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
+ * 9999-12-31T23:59:59Z inclusive.
+ * @type int $nanos
+ * Non-negative fractions of a second at nanosecond resolution. Negative
+ * second values with fractions must still have non-negative nanos values
+ * that count forward in time. Must be from 0 to 999,999,999
+ * inclusive.
+ * }
+ */
+ public function __construct($data = NULL) {
\GPBMetadata\Google\Protobuf\Timestamp::initOnce();
- parent::__construct();
+ parent::__construct($data);
}
/**
@@ -156,17 +175,13 @@ class Timestamp extends \Google\Protobuf\Internal\Message
return $this;
}
- /**
+ /*
* Converts PHP DateTime to Timestamp.
*
- * @param DateTime $datetime
+ * @param \DateTime $datetime
*/
- public function fromDateTime($datetime)
+ public function fromDateTime(\DateTime $datetime)
{
- if (get_class($datetime) !== \DateTime::class) {
- trigger_error("Given parameter is not a DateTime.",
- E_USER_ERROR);
- }
$this->seconds = $datetime->format('U');
$this->nanos = 0;
}
@@ -174,7 +189,7 @@ class Timestamp extends \Google\Protobuf\Internal\Message
/**
* Converts Timestamp to PHP DateTime. Nano second is ignored.
*
- * @return DateTime $datetime
+ * @return \DateTime $datetime
*/
public function toDateTime()
{