Source File
timestamp.go
Belonging Package
github.com/golang/protobuf/ptypes
package ptypes
import (
timestamppb
)
maxValidSeconds = 253402300800
)
func () *timestamppb.Timestamp {
, := TimestampProto(time.Now())
if != nil {
panic("ptypes: time.Now() out of Timestamp range")
}
return
}
func ( time.Time) (*timestamppb.Timestamp, error) {
:= ×tamppb.Timestamp{
Seconds: .Unix(),
Nanos: int32(.Nanosecond()),
}
if := validateTimestamp(); != nil {
return nil,
}
return , nil
}
func ( *timestamppb.Timestamp) string {
, := Timestamp()
if != nil {
return fmt.Sprintf("(%v)", )
}
return .Format(time.RFC3339Nano)
}
func ( *timestamppb.Timestamp) error {
if == nil {
return errors.New("timestamp: nil Timestamp")
}
if .Seconds < minValidSeconds {
return fmt.Errorf("timestamp: %v before 0001-01-01", )
}
if .Seconds >= maxValidSeconds {
return fmt.Errorf("timestamp: %v after 10000-01-01", )
}
if .Nanos < 0 || .Nanos >= 1e9 {
return fmt.Errorf("timestamp: %v: nanos not in range [0, 1e9)", )
}
return nil
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |