Feng Xiao | 96e379f | 2015-02-09 12:21:49 +0800 | [diff] [blame] | 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. |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 30 | |
Feng Xiao | 96e379f | 2015-02-09 12:21:49 +0800 | [diff] [blame] | 31 | syntax = "proto3"; |
| 32 | |
| 33 | package google.protobuf; |
| 34 | |
Jon Skeet | 739d13d | 2015-07-14 14:26:31 +0100 | [diff] [blame] | 35 | option csharp_namespace = "Google.Protobuf.WellKnownTypes"; |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 36 | option cc_enable_arenas = true; |
| 37 | option java_package = "com.google.protobuf"; |
| 38 | option java_outer_classname = "TimestampProto"; |
| 39 | option java_multiple_files = true; |
| 40 | option java_generate_equals_and_hash = true; |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 41 | option objc_class_prefix = "GPB"; |
Feng Xiao | 96e379f | 2015-02-09 12:21:49 +0800 | [diff] [blame] | 42 | |
Feng Xiao | 96e379f | 2015-02-09 12:21:49 +0800 | [diff] [blame] | 43 | // A Timestamp represents a point in time independent of any time zone |
| 44 | // or calendar, represented as seconds and fractions of seconds at |
| 45 | // nanosecond resolution in UTC Epoch time. It is encoded using the |
| 46 | // Proleptic Gregorian Calendar which extends the Gregorian calendar |
| 47 | // backwards to year one. It is encoded assuming all minutes are 60 |
| 48 | // seconds long, i.e. leap seconds are "smeared" so that no leap second |
| 49 | // table is needed for interpretation. Range is from |
| 50 | // 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. |
| 51 | // By restricting to that range, we ensure that we can convert to |
Feng Xiao | ca9d1a0 | 2015-04-20 11:30:31 -0700 | [diff] [blame] | 52 | // and from RFC 3339 date strings. |
| 53 | // See [https://www.ietf.org/rfc/rfc3339.txt](https://www.ietf.org/rfc/rfc3339.txt). |
Feng Xiao | 96e379f | 2015-02-09 12:21:49 +0800 | [diff] [blame] | 54 | // |
Feng Xiao | ca9d1a0 | 2015-04-20 11:30:31 -0700 | [diff] [blame] | 55 | // Example 1: Compute Timestamp from POSIX `time()`. |
Feng Xiao | 96e379f | 2015-02-09 12:21:49 +0800 | [diff] [blame] | 56 | // |
| 57 | // Timestamp timestamp; |
| 58 | // timestamp.set_seconds(time(NULL)); |
| 59 | // timestamp.set_nanos(0); |
| 60 | // |
Feng Xiao | ca9d1a0 | 2015-04-20 11:30:31 -0700 | [diff] [blame] | 61 | // Example 2: Compute Timestamp from POSIX `gettimeofday()`. |
Feng Xiao | 96e379f | 2015-02-09 12:21:49 +0800 | [diff] [blame] | 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 | // |
Feng Xiao | ca9d1a0 | 2015-04-20 11:30:31 -0700 | [diff] [blame] | 70 | // Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`. |
Feng Xiao | 96e379f | 2015-02-09 12:21:49 +0800 | [diff] [blame] | 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 | // |
Feng Xiao | ca9d1a0 | 2015-04-20 11:30:31 -0700 | [diff] [blame] | 82 | // Example 4: Compute Timestamp from Java `System.currentTimeMillis()`. |
Feng Xiao | 96e379f | 2015-02-09 12:21:49 +0800 | [diff] [blame] | 83 | // |
| 84 | // long millis = System.currentTimeMillis(); |
| 85 | // |
| 86 | // Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000) |
| 87 | // .setNanos((int) ((millis % 1000) * 1000000)).build(); |
| 88 | // |
Feng Xiao | 96e379f | 2015-02-09 12:21:49 +0800 | [diff] [blame] | 89 | // |
Jisi Liu | b0f6611 | 2015-08-21 11:18:45 -0700 | [diff] [blame] | 90 | // Example 5: Compute Timestamp from current time in Python. |
| 91 | // |
| 92 | // now = time.time() |
| 93 | // seconds = int(now) |
| 94 | // nanos = int((now - seconds) * 10**9) |
Feng Xiao | 96e379f | 2015-02-09 12:21:49 +0800 | [diff] [blame] | 95 | // timestamp = Timestamp(seconds=seconds, nanos=nanos) |
| 96 | // |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 97 | // |
Feng Xiao | 96e379f | 2015-02-09 12:21:49 +0800 | [diff] [blame] | 98 | message Timestamp { |
Jisi Liu | b0f6611 | 2015-08-21 11:18:45 -0700 | [diff] [blame] | 99 | |
Feng Xiao | 96e379f | 2015-02-09 12:21:49 +0800 | [diff] [blame] | 100 | // Represents seconds of UTC time since Unix epoch |
| 101 | // 1970-01-01T00:00:00Z. Must be from from 0001-01-01T00:00:00Z to |
| 102 | // 9999-12-31T23:59:59Z inclusive. |
| 103 | int64 seconds = 1; |
| 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 | int32 nanos = 2; |
| 110 | } |