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