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