|
| 1 | +/* eslint-disable */ |
| 2 | +import * as _m0 from "protobufjs/minimal"; |
| 3 | + |
| 4 | +export const protobufPackage = "google.protobuf"; |
| 5 | + |
| 6 | +/** |
| 7 | + * A Timestamp represents a point in time independent of any time zone or local |
| 8 | + * calendar, encoded as a count of seconds and fractions of seconds at |
| 9 | + * nanosecond resolution. The count is relative to an epoch at UTC midnight on |
| 10 | + * January 1, 1970, in the proleptic Gregorian calendar which extends the |
| 11 | + * Gregorian calendar backwards to year one. |
| 12 | + * |
| 13 | + * All minutes are 60 seconds long. Leap seconds are "smeared" so that no leap |
| 14 | + * second table is needed for interpretation, using a [24-hour linear |
| 15 | + * smear](https://developers.google.com/time/smear). |
| 16 | + * |
| 17 | + * The range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. By |
| 18 | + * restricting to that range, we ensure that we can convert to and from [RFC |
| 19 | + * 3339](https://www.ietf.org/rfc/rfc3339.txt) date strings. |
| 20 | + * |
| 21 | + * # Examples |
| 22 | + * |
| 23 | + * Example 1: Compute Timestamp from POSIX `time()`. |
| 24 | + * |
| 25 | + * Timestamp timestamp; |
| 26 | + * timestamp.set_seconds(time(NULL)); |
| 27 | + * timestamp.set_nanos(0); |
| 28 | + * |
| 29 | + * Example 2: Compute Timestamp from POSIX `gettimeofday()`. |
| 30 | + * |
| 31 | + * struct timeval tv; |
| 32 | + * gettimeofday(&tv, NULL); |
| 33 | + * |
| 34 | + * Timestamp timestamp; |
| 35 | + * timestamp.set_seconds(tv.tv_sec); |
| 36 | + * timestamp.set_nanos(tv.tv_usec * 1000); |
| 37 | + * |
| 38 | + * Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`. |
| 39 | + * |
| 40 | + * FILETIME ft; |
| 41 | + * GetSystemTimeAsFileTime(&ft); |
| 42 | + * UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime; |
| 43 | + * |
| 44 | + * // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z |
| 45 | + * // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z. |
| 46 | + * Timestamp timestamp; |
| 47 | + * timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL)); |
| 48 | + * timestamp.set_nanos((INT32) ((ticks % 10000000) * 100)); |
| 49 | + * |
| 50 | + * Example 4: Compute Timestamp from Java `System.currentTimeMillis()`. |
| 51 | + * |
| 52 | + * long millis = System.currentTimeMillis(); |
| 53 | + * |
| 54 | + * Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000) |
| 55 | + * .setNanos((int) ((millis % 1000) * 1000000)).build(); |
| 56 | + * |
| 57 | + * Example 5: Compute Timestamp from Java `Instant.now()`. |
| 58 | + * |
| 59 | + * Instant now = Instant.now(); |
| 60 | + * |
| 61 | + * Timestamp timestamp = |
| 62 | + * Timestamp.newBuilder().setSeconds(now.getEpochSecond()) |
| 63 | + * .setNanos(now.getNano()).build(); |
| 64 | + * |
| 65 | + * Example 6: Compute Timestamp from current time in Python. |
| 66 | + * |
| 67 | + * timestamp = Timestamp() |
| 68 | + * timestamp.GetCurrentTime() |
| 69 | + * |
| 70 | + * # JSON Mapping |
| 71 | + * |
| 72 | + * In JSON format, the Timestamp type is encoded as a string in the |
| 73 | + * [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the |
| 74 | + * format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z" |
| 75 | + * where {year} is always expressed using four digits while {month}, {day}, |
| 76 | + * {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional |
| 77 | + * seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution), |
| 78 | + * are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone |
| 79 | + * is required. A proto3 JSON serializer should always use UTC (as indicated by |
| 80 | + * "Z") when printing the Timestamp type and a proto3 JSON parser should be |
| 81 | + * able to accept both UTC and other timezones (as indicated by an offset). |
| 82 | + * |
| 83 | + * For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past |
| 84 | + * 01:30 UTC on January 15, 2017. |
| 85 | + * |
| 86 | + * In JavaScript, one can convert a Date object to this format using the |
| 87 | + * standard |
| 88 | + * [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString) |
| 89 | + * method. In Python, a standard `datetime.datetime` object can be converted |
| 90 | + * to this format using |
| 91 | + * [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) with |
| 92 | + * the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one can use |
| 93 | + * the Joda Time's [`ISODateTimeFormat.dateTime()`]( |
| 94 | + * http://joda-time.sourceforge.net/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime() |
| 95 | + * ) to obtain a formatter capable of generating timestamps in this format. |
| 96 | + */ |
| 97 | +export interface Timestamp { |
| 98 | + /** |
| 99 | + * Represents seconds of UTC time since Unix epoch |
| 100 | + * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to |
| 101 | + * 9999-12-31T23:59:59Z inclusive. |
| 102 | + */ |
| 103 | + seconds: number; |
| 104 | + /** |
| 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 | + nanos: number; |
| 111 | +} |
| 112 | + |
| 113 | +export const Timestamp = { |
| 114 | + encode(message: Timestamp, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { |
| 115 | + if (message.seconds !== 0) { |
| 116 | + writer.uint32(8).int64(message.seconds); |
| 117 | + } |
| 118 | + if (message.nanos !== 0) { |
| 119 | + writer.uint32(16).int32(message.nanos); |
| 120 | + } |
| 121 | + return writer; |
| 122 | + }, |
| 123 | +}; |
0 commit comments