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 31 // Code generated by protoc-gen-go. DO NOT EDIT. 32 // source: google/protobuf/timestamp.proto 33 34 // Package timestamppb contains generated types for google/protobuf/timestamp.proto. 35 // 36 // The Timestamp message represents a timestamp, 37 // an instant in time since the Unix epoch (January 1st, 1970). 38 // 39 // # Conversion to a Go Time 40 // 41 // The AsTime method can be used to convert a Timestamp message to a 42 // standard Go time.Time value in UTC: 43 // 44 // t := ts.AsTime() 45 // ... // make use of t as a time.Time 46 // 47 // Converting to a time.Time is a common operation so that the extensive 48 // set of time-based operations provided by the time package can be leveraged. 49 // See https://golang.org/pkg/time for more information. 50 // 51 // The AsTime method performs the conversion on a best-effort basis. Timestamps 52 // with denormal values (e.g., nanoseconds beyond 0 and 99999999, inclusive) 53 // are normalized during the conversion to a time.Time. To manually check for 54 // invalid Timestamps per the documented limitations in timestamp.proto, 55 // additionally call the CheckValid method: 56 // 57 // if err := ts.CheckValid(); err != nil { 58 // ... // handle error 59 // } 60 // 61 // # Conversion from a Go Time 62 // 63 // The timestamppb.New function can be used to construct a Timestamp message 64 // from a standard Go time.Time value: 65 // 66 // ts := timestamppb.New(t) 67 // ... // make use of ts as a *timestamppb.Timestamp 68 // 69 // In order to construct a Timestamp representing the current time, use Now: 70 // 71 // ts := timestamppb.Now() 72 // ... // make use of ts as a *timestamppb.Timestamp 73 package timestamppb 74 75 import ( 76 protoreflect "google.golang.org/protobuf/reflect/protoreflect" 77 protoimpl "google.golang.org/protobuf/runtime/protoimpl" 78 reflect "reflect" 79 sync "sync" 80 time "time" 81 ) 82 83 // A Timestamp represents a point in time independent of any time zone or local 84 // calendar, encoded as a count of seconds and fractions of seconds at 85 // nanosecond resolution. The count is relative to an epoch at UTC midnight on 86 // January 1, 1970, in the proleptic Gregorian calendar which extends the 87 // Gregorian calendar backwards to year one. 88 // 89 // All minutes are 60 seconds long. Leap seconds are "smeared" so that no leap 90 // second table is needed for interpretation, using a [24-hour linear 91 // smear](https://developers.google.com/time/smear). 92 // 93 // The range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. By 94 // restricting to that range, we ensure that we can convert to and from [RFC 95 // 3339](https://www.ietf.org/rfc/rfc3339.txt) date strings. 96 // 97 // # Examples 98 // 99 // Example 1: Compute Timestamp from POSIX `time()`. 100 // 101 // Timestamp timestamp; 102 // timestamp.set_seconds(time(NULL)); 103 // timestamp.set_nanos(0); 104 // 105 // Example 2: Compute Timestamp from POSIX `gettimeofday()`. 106 // 107 // struct timeval tv; 108 // gettimeofday(&tv, NULL); 109 // 110 // Timestamp timestamp; 111 // timestamp.set_seconds(tv.tv_sec); 112 // timestamp.set_nanos(tv.tv_usec * 1000); 113 // 114 // Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`. 115 // 116 // FILETIME ft; 117 // GetSystemTimeAsFileTime(&ft); 118 // UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime; 119 // 120 // // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z 121 // // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z. 122 // Timestamp timestamp; 123 // timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL)); 124 // timestamp.set_nanos((INT32) ((ticks % 10000000) * 100)); 125 // 126 // Example 4: Compute Timestamp from Java `System.currentTimeMillis()`. 127 // 128 // long millis = System.currentTimeMillis(); 129 // 130 // Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000) 131 // .setNanos((int) ((millis % 1000) * 1000000)).build(); 132 // 133 // Example 5: Compute Timestamp from Java `Instant.now()`. 134 // 135 // Instant now = Instant.now(); 136 // 137 // Timestamp timestamp = 138 // Timestamp.newBuilder().setSeconds(now.getEpochSecond()) 139 // .setNanos(now.getNano()).build(); 140 // 141 // Example 6: Compute Timestamp from current time in Python. 142 // 143 // timestamp = Timestamp() 144 // timestamp.GetCurrentTime() 145 // 146 // # JSON Mapping 147 // 148 // In JSON format, the Timestamp type is encoded as a string in the 149 // [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the 150 // format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z" 151 // where {year} is always expressed using four digits while {month}, {day}, 152 // {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional 153 // seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution), 154 // are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone 155 // is required. A proto3 JSON serializer should always use UTC (as indicated by 156 // "Z") when printing the Timestamp type and a proto3 JSON parser should be 157 // able to accept both UTC and other timezones (as indicated by an offset). 158 // 159 // For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past 160 // 01:30 UTC on January 15, 2017. 161 // 162 // In JavaScript, one can convert a Date object to this format using the 163 // standard 164 // [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString) 165 // method. In Python, a standard `datetime.datetime` object can be converted 166 // to this format using 167 // [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) with 168 // the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one can use 169 // the Joda Time's [`ISODateTimeFormat.dateTime()`]( 170 // http://joda-time.sourceforge.net/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime() 171 // ) to obtain a formatter capable of generating timestamps in this format. 172 type Timestamp struct { 173 state protoimpl.MessageState 174 sizeCache protoimpl.SizeCache 175 unknownFields protoimpl.UnknownFields 176 177 // Represents seconds of UTC time since Unix epoch 178 // 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to 179 // 9999-12-31T23:59:59Z inclusive. 180 Seconds int64 `protobuf:"varint,1,opt,name=seconds,proto3" json:"seconds,omitempty"` 181 // Non-negative fractions of a second at nanosecond resolution. Negative 182 // second values with fractions must still have non-negative nanos values 183 // that count forward in time. Must be from 0 to 999,999,999 184 // inclusive. 185 Nanos int32 `protobuf:"varint,2,opt,name=nanos,proto3" json:"nanos,omitempty"` 186 } 187 188 // Now constructs a new Timestamp from the current time. 189 func Now() *Timestamp { 190 return New(time.Now()) 191 } 192 193 // New constructs a new Timestamp from the provided time.Time. 194 func New(t time.Time) *Timestamp { 195 return &Timestamp{Seconds: int64(t.Unix()), Nanos: int32(t.Nanosecond())} 196 } 197 198 // AsTime converts x to a time.Time. 199 func (x *Timestamp) AsTime() time.Time { 200 return time.Unix(int64(x.GetSeconds()), int64(x.GetNanos())).UTC() 201 } 202 203 // IsValid reports whether the timestamp is valid. 204 // It is equivalent to CheckValid == nil. 205 func (x *Timestamp) IsValid() bool { 206 return x.check() == 0 207 } 208 209 // CheckValid returns an error if the timestamp is invalid. 210 // In particular, it checks whether the value represents a date that is 211 // in the range of 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive. 212 // An error is reported for a nil Timestamp. 213 func (x *Timestamp) CheckValid() error { 214 switch x.check() { 215 case invalidNil: 216 return protoimpl.X.NewError("invalid nil Timestamp") 217 case invalidUnderflow: 218 return protoimpl.X.NewError("timestamp (%v) before 0001-01-01", x) 219 case invalidOverflow: 220 return protoimpl.X.NewError("timestamp (%v) after 9999-12-31", x) 221 case invalidNanos: 222 return protoimpl.X.NewError("timestamp (%v) has out-of-range nanos", x) 223 default: 224 return nil 225 } 226 } 227 228 const ( 229 _ = iota 230 invalidNil 231 invalidUnderflow 232 invalidOverflow 233 invalidNanos 234 ) 235 236 func (x *Timestamp) check() uint { 237 const minTimestamp = -62135596800 // Seconds between 1970-01-01T00:00:00Z and 0001-01-01T00:00:00Z, inclusive 238 const maxTimestamp = +253402300799 // Seconds between 1970-01-01T00:00:00Z and 9999-12-31T23:59:59Z, inclusive 239 secs := x.GetSeconds() 240 nanos := x.GetNanos() 241 switch { 242 case x == nil: 243 return invalidNil 244 case secs < minTimestamp: 245 return invalidUnderflow 246 case secs > maxTimestamp: 247 return invalidOverflow 248 case nanos < 0 || nanos >= 1e9: 249 return invalidNanos 250 default: 251 return 0 252 } 253 } 254 255 func (x *Timestamp) Reset() { 256 *x = Timestamp{} 257 if protoimpl.UnsafeEnabled { 258 mi := &file_google_protobuf_timestamp_proto_msgTypes[0] 259 ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 260 ms.StoreMessageInfo(mi) 261 } 262 } 263 264 func (x *Timestamp) String() string { 265 return protoimpl.X.MessageStringOf(x) 266 } 267 268 func (*Timestamp) ProtoMessage() {} 269 270 func (x *Timestamp) ProtoReflect() protoreflect.Message { 271 mi := &file_google_protobuf_timestamp_proto_msgTypes[0] 272 if protoimpl.UnsafeEnabled && x != nil { 273 ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 274 if ms.LoadMessageInfo() == nil { 275 ms.StoreMessageInfo(mi) 276 } 277 return ms 278 } 279 return mi.MessageOf(x) 280 } 281 282 // Deprecated: Use Timestamp.ProtoReflect.Descriptor instead. 283 func (*Timestamp) Descriptor() ([]byte, []int) { 284 return file_google_protobuf_timestamp_proto_rawDescGZIP(), []int{0} 285 } 286 287 func (x *Timestamp) GetSeconds() int64 { 288 if x != nil { 289 return x.Seconds 290 } 291 return 0 292 } 293 294 func (x *Timestamp) GetNanos() int32 { 295 if x != nil { 296 return x.Nanos 297 } 298 return 0 299 } 300 301 var File_google_protobuf_timestamp_proto protoreflect.FileDescriptor 302 303 var file_google_protobuf_timestamp_proto_rawDesc = []byte{ 304 0x0a, 0x1f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 305 0x66, 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 306 0x6f, 0x12, 0x0f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 307 0x75, 0x66, 0x22, 0x3b, 0x0a, 0x09, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x12, 308 0x18, 0x0a, 0x07, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 309 0x52, 0x07, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x73, 0x12, 0x14, 0x0a, 0x05, 0x6e, 0x61, 0x6e, 310 0x6f, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x6e, 0x61, 0x6e, 0x6f, 0x73, 0x42, 311 0x85, 0x01, 0x0a, 0x13, 0x63, 0x6f, 0x6d, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 312 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x42, 0x0e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 313 0x6d, 0x70, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x32, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 314 0x65, 0x2e, 0x67, 0x6f, 0x6c, 0x61, 0x6e, 0x67, 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x70, 0x72, 0x6f, 315 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2f, 0x6b, 0x6e, 0x6f, 0x77, 316 0x6e, 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x70, 0x62, 0xf8, 0x01, 0x01, 317 0xa2, 0x02, 0x03, 0x47, 0x50, 0x42, 0xaa, 0x02, 0x1e, 0x47, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 318 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x57, 0x65, 0x6c, 0x6c, 0x4b, 0x6e, 0x6f, 319 0x77, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 320 } 321 322 var ( 323 file_google_protobuf_timestamp_proto_rawDescOnce sync.Once 324 file_google_protobuf_timestamp_proto_rawDescData = file_google_protobuf_timestamp_proto_rawDesc 325 ) 326 327 func file_google_protobuf_timestamp_proto_rawDescGZIP() []byte { 328 file_google_protobuf_timestamp_proto_rawDescOnce.Do(func() { 329 file_google_protobuf_timestamp_proto_rawDescData = protoimpl.X.CompressGZIP(file_google_protobuf_timestamp_proto_rawDescData) 330 }) 331 return file_google_protobuf_timestamp_proto_rawDescData 332 } 333 334 var file_google_protobuf_timestamp_proto_msgTypes = make([]protoimpl.MessageInfo, 1) 335 var file_google_protobuf_timestamp_proto_goTypes = []interface{}{ 336 (*Timestamp)(nil), // 0: google.protobuf.Timestamp 337 } 338 var file_google_protobuf_timestamp_proto_depIdxs = []int32{ 339 0, // [0:0] is the sub-list for method output_type 340 0, // [0:0] is the sub-list for method input_type 341 0, // [0:0] is the sub-list for extension type_name 342 0, // [0:0] is the sub-list for extension extendee 343 0, // [0:0] is the sub-list for field type_name 344 } 345 346 func init() { file_google_protobuf_timestamp_proto_init() } 347 func file_google_protobuf_timestamp_proto_init() { 348 if File_google_protobuf_timestamp_proto != nil { 349 return 350 } 351 if !protoimpl.UnsafeEnabled { 352 file_google_protobuf_timestamp_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { 353 switch v := v.(*Timestamp); i { 354 case 0: 355 return &v.state 356 case 1: 357 return &v.sizeCache 358 case 2: 359 return &v.unknownFields 360 default: 361 return nil 362 } 363 } 364 } 365 type x struct{} 366 out := protoimpl.TypeBuilder{ 367 File: protoimpl.DescBuilder{ 368 GoPackagePath: reflect.TypeOf(x{}).PkgPath(), 369 RawDescriptor: file_google_protobuf_timestamp_proto_rawDesc, 370 NumEnums: 0, 371 NumMessages: 1, 372 NumExtensions: 0, 373 NumServices: 0, 374 }, 375 GoTypes: file_google_protobuf_timestamp_proto_goTypes, 376 DependencyIndexes: file_google_protobuf_timestamp_proto_depIdxs, 377 MessageInfos: file_google_protobuf_timestamp_proto_msgTypes, 378 }.Build() 379 File_google_protobuf_timestamp_proto = out.File 380 file_google_protobuf_timestamp_proto_rawDesc = nil 381 file_google_protobuf_timestamp_proto_goTypes = nil 382 file_google_protobuf_timestamp_proto_depIdxs = nil 383 } 384