github.com/GoogleCloudPlatform/testgrid@v0.0.174/web/src/gen/google/protobuf/timestamp.ts (about) 1 // @generated by protobuf-ts 2.8.3 with parameter long_type_string 2 // @generated from protobuf file "google/protobuf/timestamp.proto" (package "google.protobuf", syntax proto3) 3 // tslint:disable 4 // 5 // Protocol Buffers - Google's data interchange format 6 // Copyright 2008 Google Inc. All rights reserved. 7 // https://developers.google.com/protocol-buffers/ 8 // 9 // Redistribution and use in source and binary forms, with or without 10 // modification, are permitted provided that the following conditions are 11 // met: 12 // 13 // * Redistributions of source code must retain the above copyright 14 // notice, this list of conditions and the following disclaimer. 15 // * Redistributions in binary form must reproduce the above 16 // copyright notice, this list of conditions and the following disclaimer 17 // in the documentation and/or other materials provided with the 18 // distribution. 19 // * Neither the name of Google Inc. nor the names of its 20 // contributors may be used to endorse or promote products derived from 21 // this software without specific prior written permission. 22 // 23 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 // 35 import type { BinaryWriteOptions } from "@protobuf-ts/runtime"; 36 import type { IBinaryWriter } from "@protobuf-ts/runtime"; 37 import { WireType } from "@protobuf-ts/runtime"; 38 import type { BinaryReadOptions } from "@protobuf-ts/runtime"; 39 import type { IBinaryReader } from "@protobuf-ts/runtime"; 40 import { UnknownFieldHandler } from "@protobuf-ts/runtime"; 41 import type { PartialMessage } from "@protobuf-ts/runtime"; 42 import { reflectionMergePartial } from "@protobuf-ts/runtime"; 43 import { MESSAGE_TYPE } from "@protobuf-ts/runtime"; 44 import { typeofJsonValue } from "@protobuf-ts/runtime"; 45 import type { JsonValue } from "@protobuf-ts/runtime"; 46 import type { JsonReadOptions } from "@protobuf-ts/runtime"; 47 import type { JsonWriteOptions } from "@protobuf-ts/runtime"; 48 import { PbLong } from "@protobuf-ts/runtime"; 49 import { MessageType } from "@protobuf-ts/runtime"; 50 /** 51 * A Timestamp represents a point in time independent of any time zone or local 52 * calendar, encoded as a count of seconds and fractions of seconds at 53 * nanosecond resolution. The count is relative to an epoch at UTC midnight on 54 * January 1, 1970, in the proleptic Gregorian calendar which extends the 55 * Gregorian calendar backwards to year one. 56 * 57 * All minutes are 60 seconds long. Leap seconds are "smeared" so that no leap 58 * second table is needed for interpretation, using a [24-hour linear 59 * smear](https://developers.google.com/time/smear). 60 * 61 * The range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. By 62 * restricting to that range, we ensure that we can convert to and from [RFC 63 * 3339](https://www.ietf.org/rfc/rfc3339.txt) date strings. 64 * 65 * # Examples 66 * 67 * Example 1: Compute Timestamp from POSIX `time()`. 68 * 69 * Timestamp timestamp; 70 * timestamp.set_seconds(time(NULL)); 71 * timestamp.set_nanos(0); 72 * 73 * Example 2: Compute Timestamp from POSIX `gettimeofday()`. 74 * 75 * struct timeval tv; 76 * gettimeofday(&tv, NULL); 77 * 78 * Timestamp timestamp; 79 * timestamp.set_seconds(tv.tv_sec); 80 * timestamp.set_nanos(tv.tv_usec * 1000); 81 * 82 * Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`. 83 * 84 * FILETIME ft; 85 * GetSystemTimeAsFileTime(&ft); 86 * UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime; 87 * 88 * // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z 89 * // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z. 90 * Timestamp timestamp; 91 * timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL)); 92 * timestamp.set_nanos((INT32) ((ticks % 10000000) * 100)); 93 * 94 * Example 4: Compute Timestamp from Java `System.currentTimeMillis()`. 95 * 96 * long millis = System.currentTimeMillis(); 97 * 98 * Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000) 99 * .setNanos((int) ((millis % 1000) * 1000000)).build(); 100 * 101 * Example 5: Compute Timestamp from Java `Instant.now()`. 102 * 103 * Instant now = Instant.now(); 104 * 105 * Timestamp timestamp = 106 * Timestamp.newBuilder().setSeconds(now.getEpochSecond()) 107 * .setNanos(now.getNano()).build(); 108 * 109 * Example 6: Compute Timestamp from current time in Python. 110 * 111 * timestamp = Timestamp() 112 * timestamp.GetCurrentTime() 113 * 114 * # JSON Mapping 115 * 116 * In JSON format, the Timestamp type is encoded as a string in the 117 * [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the 118 * format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z" 119 * where {year} is always expressed using four digits while {month}, {day}, 120 * {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional 121 * seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution), 122 * are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone 123 * is required. A proto3 JSON serializer should always use UTC (as indicated by 124 * "Z") when printing the Timestamp type and a proto3 JSON parser should be 125 * able to accept both UTC and other timezones (as indicated by an offset). 126 * 127 * For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past 128 * 01:30 UTC on January 15, 2017. 129 * 130 * In JavaScript, one can convert a Date object to this format using the 131 * standard 132 * [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString) 133 * method. In Python, a standard `datetime.datetime` object can be converted 134 * to this format using 135 * [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) with 136 * the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one can use 137 * the Joda Time's [`ISODateTimeFormat.dateTime()`]( 138 * http://joda-time.sourceforge.net/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime() 139 * ) to obtain a formatter capable of generating timestamps in this format. 140 * 141 * 142 * @generated from protobuf message google.protobuf.Timestamp 143 */ 144 export interface Timestamp { 145 /** 146 * Represents seconds of UTC time since Unix epoch 147 * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to 148 * 9999-12-31T23:59:59Z inclusive. 149 * 150 * @generated from protobuf field: int64 seconds = 1; 151 */ 152 seconds: string; 153 /** 154 * Non-negative fractions of a second at nanosecond resolution. Negative 155 * second values with fractions must still have non-negative nanos values 156 * that count forward in time. Must be from 0 to 999,999,999 157 * inclusive. 158 * 159 * @generated from protobuf field: int32 nanos = 2; 160 */ 161 nanos: number; 162 } 163 // @generated message type with reflection information, may provide speed optimized methods 164 class Timestamp$Type extends MessageType<Timestamp> { 165 constructor() { 166 super("google.protobuf.Timestamp", [ 167 { no: 1, name: "seconds", kind: "scalar", T: 3 /*ScalarType.INT64*/ }, 168 { no: 2, name: "nanos", kind: "scalar", T: 5 /*ScalarType.INT32*/ } 169 ]); 170 } 171 /** 172 * Creates a new `Timestamp` for the current time. 173 */ 174 now(): Timestamp { 175 const msg = this.create(); 176 const ms = Date.now(); 177 msg.seconds = PbLong.from(Math.floor(ms / 1000)).toString(); 178 msg.nanos = (ms % 1000) * 1000000; 179 return msg; 180 } 181 /** 182 * Converts a `Timestamp` to a JavaScript Date. 183 */ 184 toDate(message: Timestamp): Date { 185 return new Date(PbLong.from(message.seconds).toNumber() * 1000 + Math.ceil(message.nanos / 1000000)); 186 } 187 /** 188 * Converts a JavaScript Date to a `Timestamp`. 189 */ 190 fromDate(date: Date): Timestamp { 191 const msg = this.create(); 192 const ms = date.getTime(); 193 msg.seconds = PbLong.from(Math.floor(ms / 1000)).toString(); 194 msg.nanos = (ms % 1000) * 1000000; 195 return msg; 196 } 197 /** 198 * In JSON format, the `Timestamp` type is encoded as a string 199 * in the RFC 3339 format. 200 */ 201 internalJsonWrite(message: Timestamp, options: JsonWriteOptions): JsonValue { 202 let ms = PbLong.from(message.seconds).toNumber() * 1000; 203 if (ms < Date.parse("0001-01-01T00:00:00Z") || ms > Date.parse("9999-12-31T23:59:59Z")) 204 throw new Error("Unable to encode Timestamp to JSON. Must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive."); 205 if (message.nanos < 0) 206 throw new Error("Unable to encode invalid Timestamp to JSON. Nanos must not be negative."); 207 let z = "Z"; 208 if (message.nanos > 0) { 209 let nanosStr = (message.nanos + 1000000000).toString().substring(1); 210 if (nanosStr.substring(3) === "000000") 211 z = "." + nanosStr.substring(0, 3) + "Z"; 212 else if (nanosStr.substring(6) === "000") 213 z = "." + nanosStr.substring(0, 6) + "Z"; 214 else 215 z = "." + nanosStr + "Z"; 216 } 217 return new Date(ms).toISOString().replace(".000Z", z); 218 } 219 /** 220 * In JSON format, the `Timestamp` type is encoded as a string 221 * in the RFC 3339 format. 222 */ 223 internalJsonRead(json: JsonValue, options: JsonReadOptions, target?: Timestamp): Timestamp { 224 if (typeof json !== "string") 225 throw new Error("Unable to parse Timestamp from JSON " + typeofJsonValue(json) + "."); 226 let matches = json.match(/^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(?:Z|\.([0-9]{3,9})Z|([+-][0-9][0-9]:[0-9][0-9]))$/); 227 if (!matches) 228 throw new Error("Unable to parse Timestamp from JSON. Invalid format."); 229 let ms = Date.parse(matches[1] + "-" + matches[2] + "-" + matches[3] + "T" + matches[4] + ":" + matches[5] + ":" + matches[6] + (matches[8] ? matches[8] : "Z")); 230 if (Number.isNaN(ms)) 231 throw new Error("Unable to parse Timestamp from JSON. Invalid value."); 232 if (ms < Date.parse("0001-01-01T00:00:00Z") || ms > Date.parse("9999-12-31T23:59:59Z")) 233 throw new globalThis.Error("Unable to parse Timestamp from JSON. Must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive."); 234 if (!target) 235 target = this.create(); 236 target.seconds = PbLong.from(ms / 1000).toString(); 237 target.nanos = 0; 238 if (matches[7]) 239 target.nanos = (parseInt("1" + matches[7] + "0".repeat(9 - matches[7].length)) - 1000000000); 240 return target; 241 } 242 create(value?: PartialMessage<Timestamp>): Timestamp { 243 const message = { seconds: "0", nanos: 0 }; 244 globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this }); 245 if (value !== undefined) 246 reflectionMergePartial<Timestamp>(this, message, value); 247 return message; 248 } 249 internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: Timestamp): Timestamp { 250 let message = target ?? this.create(), end = reader.pos + length; 251 while (reader.pos < end) { 252 let [fieldNo, wireType] = reader.tag(); 253 switch (fieldNo) { 254 case /* int64 seconds */ 1: 255 message.seconds = reader.int64().toString(); 256 break; 257 case /* int32 nanos */ 2: 258 message.nanos = reader.int32(); 259 break; 260 default: 261 let u = options.readUnknownField; 262 if (u === "throw") 263 throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); 264 let d = reader.skip(wireType); 265 if (u !== false) 266 (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); 267 } 268 } 269 return message; 270 } 271 internalBinaryWrite(message: Timestamp, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { 272 /* int64 seconds = 1; */ 273 if (message.seconds !== "0") 274 writer.tag(1, WireType.Varint).int64(message.seconds); 275 /* int32 nanos = 2; */ 276 if (message.nanos !== 0) 277 writer.tag(2, WireType.Varint).int32(message.nanos); 278 let u = options.writeUnknownFields; 279 if (u !== false) 280 (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); 281 return writer; 282 } 283 } 284 /** 285 * @generated MessageType for protobuf message google.protobuf.Timestamp 286 */ 287 export const Timestamp = new Timestamp$Type();