1ffe3c632Sopenharmony_ci<?php 2ffe3c632Sopenharmony_ci# Generated by the protocol buffer compiler. DO NOT EDIT! 3ffe3c632Sopenharmony_ci# source: google/protobuf/timestamp.proto 4ffe3c632Sopenharmony_ci 5ffe3c632Sopenharmony_cinamespace Google\Protobuf; 6ffe3c632Sopenharmony_ci 7ffe3c632Sopenharmony_ciuse Google\Protobuf\Internal\GPBType; 8ffe3c632Sopenharmony_ciuse Google\Protobuf\Internal\RepeatedField; 9ffe3c632Sopenharmony_ciuse Google\Protobuf\Internal\GPBUtil; 10ffe3c632Sopenharmony_ci 11ffe3c632Sopenharmony_ci/** 12ffe3c632Sopenharmony_ci * A Timestamp represents a point in time independent of any time zone 13ffe3c632Sopenharmony_ci * or calendar, represented as seconds and fractions of seconds at 14ffe3c632Sopenharmony_ci * nanosecond resolution in UTC Epoch time. It is encoded using the 15ffe3c632Sopenharmony_ci * Proleptic Gregorian Calendar which extends the Gregorian calendar 16ffe3c632Sopenharmony_ci * backwards to year one. It is encoded assuming all minutes are 60 17ffe3c632Sopenharmony_ci * seconds long, i.e. leap seconds are "smeared" so that no leap second 18ffe3c632Sopenharmony_ci * table is needed for interpretation. Range is from 19ffe3c632Sopenharmony_ci * 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. 20ffe3c632Sopenharmony_ci * By restricting to that range, we ensure that we can convert to 21ffe3c632Sopenharmony_ci * and from RFC 3339 date strings. 22ffe3c632Sopenharmony_ci * See [https://www.ietf.org/rfc/rfc3339.txt](https://www.ietf.org/rfc/rfc3339.txt). 23ffe3c632Sopenharmony_ci * # Examples 24ffe3c632Sopenharmony_ci * Example 1: Compute Timestamp from POSIX `time()`. 25ffe3c632Sopenharmony_ci * Timestamp timestamp; 26ffe3c632Sopenharmony_ci * timestamp.set_seconds(time(NULL)); 27ffe3c632Sopenharmony_ci * timestamp.set_nanos(0); 28ffe3c632Sopenharmony_ci * Example 2: Compute Timestamp from POSIX `gettimeofday()`. 29ffe3c632Sopenharmony_ci * struct timeval tv; 30ffe3c632Sopenharmony_ci * gettimeofday(&tv, NULL); 31ffe3c632Sopenharmony_ci * Timestamp timestamp; 32ffe3c632Sopenharmony_ci * timestamp.set_seconds(tv.tv_sec); 33ffe3c632Sopenharmony_ci * timestamp.set_nanos(tv.tv_usec * 1000); 34ffe3c632Sopenharmony_ci * Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`. 35ffe3c632Sopenharmony_ci * FILETIME ft; 36ffe3c632Sopenharmony_ci * GetSystemTimeAsFileTime(&ft); 37ffe3c632Sopenharmony_ci * UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime; 38ffe3c632Sopenharmony_ci * // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z 39ffe3c632Sopenharmony_ci * // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z. 40ffe3c632Sopenharmony_ci * Timestamp timestamp; 41ffe3c632Sopenharmony_ci * timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL)); 42ffe3c632Sopenharmony_ci * timestamp.set_nanos((INT32) ((ticks % 10000000) * 100)); 43ffe3c632Sopenharmony_ci * Example 4: Compute Timestamp from Java `System.currentTimeMillis()`. 44ffe3c632Sopenharmony_ci * long millis = System.currentTimeMillis(); 45ffe3c632Sopenharmony_ci * Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000) 46ffe3c632Sopenharmony_ci * .setNanos((int) ((millis % 1000) * 1000000)).build(); 47ffe3c632Sopenharmony_ci * Example 5: Compute Timestamp from current time in Python. 48ffe3c632Sopenharmony_ci * timestamp = Timestamp() 49ffe3c632Sopenharmony_ci * timestamp.GetCurrentTime() 50ffe3c632Sopenharmony_ci * # JSON Mapping 51ffe3c632Sopenharmony_ci * In JSON format, the Timestamp type is encoded as a string in the 52ffe3c632Sopenharmony_ci * [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the 53ffe3c632Sopenharmony_ci * format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z" 54ffe3c632Sopenharmony_ci * where {year} is always expressed using four digits while {month}, {day}, 55ffe3c632Sopenharmony_ci * {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional 56ffe3c632Sopenharmony_ci * seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution), 57ffe3c632Sopenharmony_ci * are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone 58ffe3c632Sopenharmony_ci * is required. A proto3 JSON serializer should always use UTC (as indicated by 59ffe3c632Sopenharmony_ci * "Z") when printing the Timestamp type and a proto3 JSON parser should be 60ffe3c632Sopenharmony_ci * able to accept both UTC and other timezones (as indicated by an offset). 61ffe3c632Sopenharmony_ci * For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past 62ffe3c632Sopenharmony_ci * 01:30 UTC on January 15, 2017. 63ffe3c632Sopenharmony_ci * In JavaScript, one can convert a Date object to this format using the 64ffe3c632Sopenharmony_ci * standard [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString] 65ffe3c632Sopenharmony_ci * method. In Python, a standard `datetime.datetime` object can be converted 66ffe3c632Sopenharmony_ci * to this format using [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) 67ffe3c632Sopenharmony_ci * with the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one 68ffe3c632Sopenharmony_ci * can use the Joda Time's [`ISODateTimeFormat.dateTime()`]( 69ffe3c632Sopenharmony_ci * http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime-- 70ffe3c632Sopenharmony_ci * ) to obtain a formatter capable of generating timestamps in this format. 71ffe3c632Sopenharmony_ci * 72ffe3c632Sopenharmony_ci * Generated from protobuf message <code>google.protobuf.Timestamp</code> 73ffe3c632Sopenharmony_ci */ 74ffe3c632Sopenharmony_ciclass Timestamp extends \Google\Protobuf\Internal\Message 75ffe3c632Sopenharmony_ci{ 76ffe3c632Sopenharmony_ci /** 77ffe3c632Sopenharmony_ci * Represents seconds of UTC time since Unix epoch 78ffe3c632Sopenharmony_ci * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to 79ffe3c632Sopenharmony_ci * 9999-12-31T23:59:59Z inclusive. 80ffe3c632Sopenharmony_ci * 81ffe3c632Sopenharmony_ci * Generated from protobuf field <code>int64 seconds = 1;</code> 82ffe3c632Sopenharmony_ci */ 83ffe3c632Sopenharmony_ci private $seconds = 0; 84ffe3c632Sopenharmony_ci /** 85ffe3c632Sopenharmony_ci * Non-negative fractions of a second at nanosecond resolution. Negative 86ffe3c632Sopenharmony_ci * second values with fractions must still have non-negative nanos values 87ffe3c632Sopenharmony_ci * that count forward in time. Must be from 0 to 999,999,999 88ffe3c632Sopenharmony_ci * inclusive. 89ffe3c632Sopenharmony_ci * 90ffe3c632Sopenharmony_ci * Generated from protobuf field <code>int32 nanos = 2;</code> 91ffe3c632Sopenharmony_ci */ 92ffe3c632Sopenharmony_ci private $nanos = 0; 93ffe3c632Sopenharmony_ci 94ffe3c632Sopenharmony_ci /** 95ffe3c632Sopenharmony_ci * Constructor. 96ffe3c632Sopenharmony_ci * 97ffe3c632Sopenharmony_ci * @param array $data { 98ffe3c632Sopenharmony_ci * Optional. Data for populating the Message object. 99ffe3c632Sopenharmony_ci * 100ffe3c632Sopenharmony_ci * @type int|string $seconds 101ffe3c632Sopenharmony_ci * Represents seconds of UTC time since Unix epoch 102ffe3c632Sopenharmony_ci * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to 103ffe3c632Sopenharmony_ci * 9999-12-31T23:59:59Z inclusive. 104ffe3c632Sopenharmony_ci * @type int $nanos 105ffe3c632Sopenharmony_ci * Non-negative fractions of a second at nanosecond resolution. Negative 106ffe3c632Sopenharmony_ci * second values with fractions must still have non-negative nanos values 107ffe3c632Sopenharmony_ci * that count forward in time. Must be from 0 to 999,999,999 108ffe3c632Sopenharmony_ci * inclusive. 109ffe3c632Sopenharmony_ci * } 110ffe3c632Sopenharmony_ci */ 111ffe3c632Sopenharmony_ci public function __construct($data = NULL) { 112ffe3c632Sopenharmony_ci \GPBMetadata\Google\Protobuf\Timestamp::initOnce(); 113ffe3c632Sopenharmony_ci parent::__construct($data); 114ffe3c632Sopenharmony_ci } 115ffe3c632Sopenharmony_ci 116ffe3c632Sopenharmony_ci /** 117ffe3c632Sopenharmony_ci * Represents seconds of UTC time since Unix epoch 118ffe3c632Sopenharmony_ci * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to 119ffe3c632Sopenharmony_ci * 9999-12-31T23:59:59Z inclusive. 120ffe3c632Sopenharmony_ci * 121ffe3c632Sopenharmony_ci * Generated from protobuf field <code>int64 seconds = 1;</code> 122ffe3c632Sopenharmony_ci * @return int|string 123ffe3c632Sopenharmony_ci */ 124ffe3c632Sopenharmony_ci public function getSeconds() 125ffe3c632Sopenharmony_ci { 126ffe3c632Sopenharmony_ci return $this->seconds; 127ffe3c632Sopenharmony_ci } 128ffe3c632Sopenharmony_ci 129ffe3c632Sopenharmony_ci /** 130ffe3c632Sopenharmony_ci * Represents seconds of UTC time since Unix epoch 131ffe3c632Sopenharmony_ci * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to 132ffe3c632Sopenharmony_ci * 9999-12-31T23:59:59Z inclusive. 133ffe3c632Sopenharmony_ci * 134ffe3c632Sopenharmony_ci * Generated from protobuf field <code>int64 seconds = 1;</code> 135ffe3c632Sopenharmony_ci * @param int|string $var 136ffe3c632Sopenharmony_ci * @return $this 137ffe3c632Sopenharmony_ci */ 138ffe3c632Sopenharmony_ci public function setSeconds($var) 139ffe3c632Sopenharmony_ci { 140ffe3c632Sopenharmony_ci GPBUtil::checkInt64($var); 141ffe3c632Sopenharmony_ci $this->seconds = $var; 142ffe3c632Sopenharmony_ci 143ffe3c632Sopenharmony_ci return $this; 144ffe3c632Sopenharmony_ci } 145ffe3c632Sopenharmony_ci 146ffe3c632Sopenharmony_ci /** 147ffe3c632Sopenharmony_ci * Non-negative fractions of a second at nanosecond resolution. Negative 148ffe3c632Sopenharmony_ci * second values with fractions must still have non-negative nanos values 149ffe3c632Sopenharmony_ci * that count forward in time. Must be from 0 to 999,999,999 150ffe3c632Sopenharmony_ci * inclusive. 151ffe3c632Sopenharmony_ci * 152ffe3c632Sopenharmony_ci * Generated from protobuf field <code>int32 nanos = 2;</code> 153ffe3c632Sopenharmony_ci * @return int 154ffe3c632Sopenharmony_ci */ 155ffe3c632Sopenharmony_ci public function getNanos() 156ffe3c632Sopenharmony_ci { 157ffe3c632Sopenharmony_ci return $this->nanos; 158ffe3c632Sopenharmony_ci } 159ffe3c632Sopenharmony_ci 160ffe3c632Sopenharmony_ci /** 161ffe3c632Sopenharmony_ci * Non-negative fractions of a second at nanosecond resolution. Negative 162ffe3c632Sopenharmony_ci * second values with fractions must still have non-negative nanos values 163ffe3c632Sopenharmony_ci * that count forward in time. Must be from 0 to 999,999,999 164ffe3c632Sopenharmony_ci * inclusive. 165ffe3c632Sopenharmony_ci * 166ffe3c632Sopenharmony_ci * Generated from protobuf field <code>int32 nanos = 2;</code> 167ffe3c632Sopenharmony_ci * @param int $var 168ffe3c632Sopenharmony_ci * @return $this 169ffe3c632Sopenharmony_ci */ 170ffe3c632Sopenharmony_ci public function setNanos($var) 171ffe3c632Sopenharmony_ci { 172ffe3c632Sopenharmony_ci GPBUtil::checkInt32($var); 173ffe3c632Sopenharmony_ci $this->nanos = $var; 174ffe3c632Sopenharmony_ci 175ffe3c632Sopenharmony_ci return $this; 176ffe3c632Sopenharmony_ci } 177ffe3c632Sopenharmony_ci 178ffe3c632Sopenharmony_ci /* 179ffe3c632Sopenharmony_ci * Converts PHP DateTime to Timestamp. 180ffe3c632Sopenharmony_ci * 181ffe3c632Sopenharmony_ci * @param \DateTime $datetime 182ffe3c632Sopenharmony_ci */ 183ffe3c632Sopenharmony_ci public function fromDateTime(\DateTime $datetime) 184ffe3c632Sopenharmony_ci { 185ffe3c632Sopenharmony_ci $this->seconds = $datetime->getTimestamp(); 186ffe3c632Sopenharmony_ci $this->nanos = 1000 * $datetime->format('u'); 187ffe3c632Sopenharmony_ci } 188ffe3c632Sopenharmony_ci 189ffe3c632Sopenharmony_ci /** 190ffe3c632Sopenharmony_ci * Converts Timestamp to PHP DateTime. 191ffe3c632Sopenharmony_ci * 192ffe3c632Sopenharmony_ci * @return \DateTime $datetime 193ffe3c632Sopenharmony_ci */ 194ffe3c632Sopenharmony_ci public function toDateTime() 195ffe3c632Sopenharmony_ci { 196ffe3c632Sopenharmony_ci $time = sprintf('%s.%06d', $this->seconds, $this->nanos / 1000); 197ffe3c632Sopenharmony_ci return \DateTime::createFromFormat('U.u', $time); 198ffe3c632Sopenharmony_ci } 199ffe3c632Sopenharmony_ci} 200ffe3c632Sopenharmony_ci 201