go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/milo/ui/src/proto/google/protobuf/duration.pb.ts (about) 1 /* eslint-disable */ 2 import Long from "long"; 3 import _m0 from "protobufjs/minimal"; 4 5 export const protobufPackage = "google.protobuf"; 6 7 /** 8 * A Duration represents a signed, fixed-length span of time represented 9 * as a count of seconds and fractions of seconds at nanosecond 10 * resolution. It is independent of any calendar and concepts like "day" 11 * or "month". It is related to Timestamp in that the difference between 12 * two Timestamp values is a Duration and it can be added or subtracted 13 * from a Timestamp. Range is approximately +-10,000 years. 14 * 15 * # Examples 16 * 17 * Example 1: Compute Duration from two Timestamps in pseudo code. 18 * 19 * Timestamp start = ...; 20 * Timestamp end = ...; 21 * Duration duration = ...; 22 * 23 * duration.seconds = end.seconds - start.seconds; 24 * duration.nanos = end.nanos - start.nanos; 25 * 26 * if (duration.seconds < 0 && duration.nanos > 0) { 27 * duration.seconds += 1; 28 * duration.nanos -= 1000000000; 29 * } else if (duration.seconds > 0 && duration.nanos < 0) { 30 * duration.seconds -= 1; 31 * duration.nanos += 1000000000; 32 * } 33 * 34 * Example 2: Compute Timestamp from Timestamp + Duration in pseudo code. 35 * 36 * Timestamp start = ...; 37 * Duration duration = ...; 38 * Timestamp end = ...; 39 * 40 * end.seconds = start.seconds + duration.seconds; 41 * end.nanos = start.nanos + duration.nanos; 42 * 43 * if (end.nanos < 0) { 44 * end.seconds -= 1; 45 * end.nanos += 1000000000; 46 * } else if (end.nanos >= 1000000000) { 47 * end.seconds += 1; 48 * end.nanos -= 1000000000; 49 * } 50 * 51 * Example 3: Compute Duration from datetime.timedelta in Python. 52 * 53 * td = datetime.timedelta(days=3, minutes=10) 54 * duration = Duration() 55 * duration.FromTimedelta(td) 56 * 57 * # JSON Mapping 58 * 59 * In JSON format, the Duration type is encoded as a string rather than an 60 * object, where the string ends in the suffix "s" (indicating seconds) and 61 * is preceded by the number of seconds, with nanoseconds expressed as 62 * fractional seconds. For example, 3 seconds with 0 nanoseconds should be 63 * encoded in JSON format as "3s", while 3 seconds and 1 nanosecond should 64 * be expressed in JSON format as "3.000000001s", and 3 seconds and 1 65 * microsecond should be expressed in JSON format as "3.000001s". 66 */ 67 export interface Duration { 68 /** 69 * Signed seconds of the span of time. Must be from -315,576,000,000 70 * to +315,576,000,000 inclusive. Note: these bounds are computed from: 71 * 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years 72 */ 73 readonly seconds: string; 74 /** 75 * Signed fractions of a second at nanosecond resolution of the span 76 * of time. Durations less than one second are represented with a 0 77 * `seconds` field and a positive or negative `nanos` field. For durations 78 * of one second or more, a non-zero value for the `nanos` field must be 79 * of the same sign as the `seconds` field. Must be from -999,999,999 80 * to +999,999,999 inclusive. 81 */ 82 readonly nanos: number; 83 } 84 85 function createBaseDuration(): Duration { 86 return { seconds: "0", nanos: 0 }; 87 } 88 89 export const Duration = { 90 encode(message: Duration, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { 91 if (message.seconds !== "0") { 92 writer.uint32(8).int64(message.seconds); 93 } 94 if (message.nanos !== 0) { 95 writer.uint32(16).int32(message.nanos); 96 } 97 return writer; 98 }, 99 100 decode(input: _m0.Reader | Uint8Array, length?: number): Duration { 101 const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); 102 let end = length === undefined ? reader.len : reader.pos + length; 103 const message = createBaseDuration() as any; 104 while (reader.pos < end) { 105 const tag = reader.uint32(); 106 switch (tag >>> 3) { 107 case 1: 108 if (tag !== 8) { 109 break; 110 } 111 112 message.seconds = longToString(reader.int64() as Long); 113 continue; 114 case 2: 115 if (tag !== 16) { 116 break; 117 } 118 119 message.nanos = reader.int32(); 120 continue; 121 } 122 if ((tag & 7) === 4 || tag === 0) { 123 break; 124 } 125 reader.skipType(tag & 7); 126 } 127 return message; 128 }, 129 130 fromJSON(object: any): Duration { 131 return { 132 seconds: isSet(object.seconds) ? globalThis.String(object.seconds) : "0", 133 nanos: isSet(object.nanos) ? globalThis.Number(object.nanos) : 0, 134 }; 135 }, 136 137 toJSON(message: Duration): unknown { 138 const obj: any = {}; 139 if (message.seconds !== "0") { 140 obj.seconds = message.seconds; 141 } 142 if (message.nanos !== 0) { 143 obj.nanos = Math.round(message.nanos); 144 } 145 return obj; 146 }, 147 148 create<I extends Exact<DeepPartial<Duration>, I>>(base?: I): Duration { 149 return Duration.fromPartial(base ?? ({} as any)); 150 }, 151 fromPartial<I extends Exact<DeepPartial<Duration>, I>>(object: I): Duration { 152 const message = createBaseDuration() as any; 153 message.seconds = object.seconds ?? "0"; 154 message.nanos = object.nanos ?? 0; 155 return message; 156 }, 157 }; 158 159 type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; 160 161 export type DeepPartial<T> = T extends Builtin ? T 162 : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>> 163 : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> 164 : T extends {} ? { [K in keyof T]?: DeepPartial<T[K]> } 165 : Partial<T>; 166 167 type KeysOfUnion<T> = T extends T ? keyof T : never; 168 export type Exact<P, I extends P> = P extends Builtin ? P 169 : P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never }; 170 171 function longToString(long: Long) { 172 return long.toString(); 173 } 174 175 if (_m0.util.Long !== Long) { 176 _m0.util.Long = Long as any; 177 _m0.configure(); 178 } 179 180 function isSet(value: any): boolean { 181 return value !== null && value !== undefined; 182 }