timestamp.proto 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // Protocol Buffers - Google's data interchange format
  2. // Copyright 2008 Google Inc. All rights reserved.
  3. // https://developers.google.com/protocol-buffers/
  4. //
  5. // Redistribution and use in source and binary forms, with or without
  6. // modification, are permitted provided that the following conditions are
  7. // met:
  8. //
  9. // * Redistributions of source code must retain the above copyright
  10. // notice, this list of conditions and the following disclaimer.
  11. // * Redistributions in binary form must reproduce the above
  12. // copyright notice, this list of conditions and the following disclaimer
  13. // in the documentation and/or other materials provided with the
  14. // distribution.
  15. // * Neither the name of Google Inc. nor the names of its
  16. // contributors may be used to endorse or promote products derived from
  17. // this software without specific prior written permission.
  18. //
  19. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  23. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  25. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. syntax = "proto3";
  31. package google.protobuf;
  32. option cc_enable_arenas = true;
  33. option go_package = "google.golang.org/protobuf/types/known/timestamppb";
  34. option java_package = "com.google.protobuf";
  35. option java_outer_classname = "TimestampProto";
  36. option java_multiple_files = true;
  37. option objc_class_prefix = "GPB";
  38. option csharp_namespace = "Google.Protobuf.WellKnownTypes";
  39. // A Timestamp represents a point in time independent of any time zone or local
  40. // calendar, encoded as a count of seconds and fractions of seconds at
  41. // nanosecond resolution. The count is relative to an epoch at UTC midnight on
  42. // January 1, 1970, in the proleptic Gregorian calendar which extends the
  43. // Gregorian calendar backwards to year one.
  44. //
  45. // All minutes are 60 seconds long. Leap seconds are "smeared" so that no leap
  46. // second table is needed for interpretation, using a [24-hour linear
  47. // smear](https://developers.google.com/time/smear).
  48. //
  49. // The range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. By
  50. // restricting to that range, we ensure that we can convert to and from [RFC
  51. // 3339](https://www.ietf.org/rfc/rfc3339.txt) date strings.
  52. //
  53. // # Examples
  54. //
  55. // Example 1: Compute Timestamp from POSIX `time()`.
  56. //
  57. // Timestamp timestamp;
  58. // timestamp.set_seconds(time(NULL));
  59. // timestamp.set_nanos(0);
  60. //
  61. // Example 2: Compute Timestamp from POSIX `gettimeofday()`.
  62. //
  63. // struct timeval tv;
  64. // gettimeofday(&tv, NULL);
  65. //
  66. // Timestamp timestamp;
  67. // timestamp.set_seconds(tv.tv_sec);
  68. // timestamp.set_nanos(tv.tv_usec * 1000);
  69. //
  70. // Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`.
  71. //
  72. // FILETIME ft;
  73. // GetSystemTimeAsFileTime(&ft);
  74. // UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
  75. //
  76. // // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z
  77. // // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z.
  78. // Timestamp timestamp;
  79. // timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL));
  80. // timestamp.set_nanos((INT32) ((ticks % 10000000) * 100));
  81. //
  82. // Example 4: Compute Timestamp from Java `System.currentTimeMillis()`.
  83. //
  84. // long millis = System.currentTimeMillis();
  85. //
  86. // Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000)
  87. // .setNanos((int) ((millis % 1000) * 1000000)).build();
  88. //
  89. // Example 5: Compute Timestamp from Java `Instant.now()`.
  90. //
  91. // Instant now = Instant.now();
  92. //
  93. // Timestamp timestamp =
  94. // Timestamp.newBuilder().setSeconds(now.getEpochSecond())
  95. // .setNanos(now.getNano()).build();
  96. //
  97. // Example 6: Compute Timestamp from current time in Python.
  98. //
  99. // timestamp = Timestamp()
  100. // timestamp.GetCurrentTime()
  101. //
  102. // # JSON Mapping
  103. //
  104. // In JSON format, the Timestamp type is encoded as a string in the
  105. // [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the
  106. // format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z"
  107. // where {year} is always expressed using four digits while {month}, {day},
  108. // {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional
  109. // seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution),
  110. // are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone
  111. // is required. A proto3 JSON serializer should always use UTC (as indicated by
  112. // "Z") when printing the Timestamp type and a proto3 JSON parser should be
  113. // able to accept both UTC and other timezones (as indicated by an offset).
  114. //
  115. // For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past
  116. // 01:30 UTC on January 15, 2017.
  117. //
  118. // In JavaScript, one can convert a Date object to this format using the
  119. // standard
  120. // [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString)
  121. // method. In Python, a standard `datetime.datetime` object can be converted
  122. // to this format using
  123. // [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) with
  124. // the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one can use
  125. // the Joda Time's [`ISODateTimeFormat.dateTime()`](
  126. // http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime%2D%2D
  127. // ) to obtain a formatter capable of generating timestamps in this format.
  128. //
  129. message Timestamp {
  130. // Represents seconds of UTC time since Unix epoch
  131. // 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
  132. // 9999-12-31T23:59:59Z inclusive.
  133. int64 seconds = 1;
  134. // Non-negative fractions of a second at nanosecond resolution. Negative
  135. // second values with fractions must still have non-negative nanos values
  136. // that count forward in time. Must be from 0 to 999,999,999
  137. // inclusive.
  138. int32 nanos = 2;
  139. }