timestamp.ts
1 // Code generated by protoc-gen-ts_proto. DO NOT EDIT. 2 // versions: 3 // protoc-gen-ts_proto v2.6.1 4 // protoc unknown 5 // source: google/protobuf/timestamp.proto 6 7 /* eslint-disable */ 8 9 /** 10 * A Timestamp represents a point in time independent of any time zone or local 11 * calendar, encoded as a count of seconds and fractions of seconds at 12 * nanosecond resolution. The count is relative to an epoch at UTC midnight on 13 * January 1, 1970, in the proleptic Gregorian calendar which extends the 14 * Gregorian calendar backwards to year one. 15 * 16 * All minutes are 60 seconds long. Leap seconds are "smeared" so that no leap 17 * second table is needed for interpretation, using a [24-hour linear 18 * smear](https://developers.google.com/time/smear). 19 * 20 * The range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. By 21 * restricting to that range, we ensure that we can convert to and from [RFC 22 * 3339](https://www.ietf.org/rfc/rfc3339.txt) date strings. 23 * 24 * # Examples 25 * 26 * Example 1: Compute Timestamp from POSIX `time()`. 27 * 28 * Timestamp timestamp; 29 * timestamp.set_seconds(time(NULL)); 30 * timestamp.set_nanos(0); 31 * 32 * Example 2: Compute Timestamp from POSIX `gettimeofday()`. 33 * 34 * struct timeval tv; 35 * gettimeofday(&tv, NULL); 36 * 37 * Timestamp timestamp; 38 * timestamp.set_seconds(tv.tv_sec); 39 * timestamp.set_nanos(tv.tv_usec * 1000); 40 * 41 * Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`. 42 * 43 * FILETIME ft; 44 * GetSystemTimeAsFileTime(&ft); 45 * UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime; 46 * 47 * // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z 48 * // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z. 49 * Timestamp timestamp; 50 * timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL)); 51 * timestamp.set_nanos((INT32) ((ticks % 10000000) * 100)); 52 * 53 * Example 4: Compute Timestamp from Java `System.currentTimeMillis()`. 54 * 55 * long millis = System.currentTimeMillis(); 56 * 57 * Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000) 58 * .setNanos((int) ((millis % 1000) * 1000000)).build(); 59 * 60 * Example 5: Compute Timestamp from Java `Instant.now()`. 61 * 62 * Instant now = Instant.now(); 63 * 64 * Timestamp timestamp = 65 * Timestamp.newBuilder().setSeconds(now.getEpochSecond()) 66 * .setNanos(now.getNano()).build(); 67 * 68 * Example 6: Compute Timestamp from current time in Python. 69 * 70 * timestamp = Timestamp() 71 * timestamp.GetCurrentTime() 72 * 73 * # JSON Mapping 74 * 75 * In JSON format, the Timestamp type is encoded as a string in the 76 * [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the 77 * format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z" 78 * where {year} is always expressed using four digits while {month}, {day}, 79 * {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional 80 * seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution), 81 * are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone 82 * is required. A proto3 JSON serializer should always use UTC (as indicated by 83 * "Z") when printing the Timestamp type and a proto3 JSON parser should be 84 * able to accept both UTC and other timezones (as indicated by an offset). 85 * 86 * For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past 87 * 01:30 UTC on January 15, 2017. 88 * 89 * In JavaScript, one can convert a Date object to this format using the 90 * standard 91 * [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString) 92 * method. In Python, a standard `datetime.datetime` object can be converted 93 * to this format using 94 * [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) with 95 * the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one can use 96 * the Joda Time's [`ISODateTimeFormat.dateTime()`]( 97 * http://joda-time.sourceforge.net/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime() 98 * ) to obtain a formatter capable of generating timestamps in this format. 99 */ 100 export interface Timestamp { 101 /** 102 * Represents seconds of UTC time since Unix epoch 103 * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to 104 * 9999-12-31T23:59:59Z inclusive. 105 */ 106 seconds?: number | undefined 107 /** 108 * Non-negative fractions of a second at nanosecond resolution. Negative 109 * second values with fractions must still have non-negative nanos values 110 * that count forward in time. Must be from 0 to 999,999,999 111 * inclusive. 112 */ 113 nanos?: number | undefined 114 } 115 116 function createBaseTimestamp(): Timestamp { 117 return { seconds: 0, nanos: 0 } 118 } 119 120 export const Timestamp: MessageFns<Timestamp> = { 121 fromJSON(object: any): Timestamp { 122 return { 123 seconds: isSet(object.seconds) ? globalThis.Number(object.seconds) : 0, 124 nanos: isSet(object.nanos) ? globalThis.Number(object.nanos) : 0, 125 } 126 }, 127 128 toJSON(message: Timestamp): unknown { 129 const obj: any = {} 130 if (message.seconds !== undefined) { 131 obj.seconds = Math.round(message.seconds) 132 } 133 if (message.nanos !== undefined) { 134 obj.nanos = Math.round(message.nanos) 135 } 136 return obj 137 }, 138 139 create<I extends Exact<DeepPartial<Timestamp>, I>>(base?: I): Timestamp { 140 return Timestamp.fromPartial(base ?? ({} as any)) 141 }, 142 fromPartial<I extends Exact<DeepPartial<Timestamp>, I>>( 143 object: I, 144 ): Timestamp { 145 const message = createBaseTimestamp() 146 message.seconds = object.seconds ?? 0 147 message.nanos = object.nanos ?? 0 148 return message 149 }, 150 } 151 152 type Builtin = 153 | Date 154 | Function 155 | Uint8Array 156 | string 157 | number 158 | boolean 159 | undefined 160 161 type DeepPartial<T> = T extends Builtin 162 ? T 163 : T extends globalThis.Array<infer U> 164 ? globalThis.Array<DeepPartial<U>> 165 : T extends ReadonlyArray<infer U> 166 ? ReadonlyArray<DeepPartial<U>> 167 : T extends {} 168 ? { [K in keyof T]?: DeepPartial<T[K]> } 169 : Partial<T> 170 171 type KeysOfUnion<T> = T extends T ? keyof T : never 172 type Exact<P, I extends P> = P extends Builtin 173 ? P 174 : P & { [K in keyof P]: Exact<P[K], I[K]> } & { 175 [K in Exclude<keyof I, KeysOfUnion<P>>]: never 176 } 177 178 function isSet(value: any): boolean { 179 return value !== null && value !== undefined 180 } 181 182 interface MessageFns<T> { 183 fromJSON(object: any): T 184 toJSON(message: T): unknown 185 create<I extends Exact<DeepPartial<T>, I>>(base?: I): T 186 fromPartial<I extends Exact<DeepPartial<T>, I>>(object: I): T 187 }