Documentation ¶
Overview ¶
Package timestamppb contains generated types for aptos/util/timestamp/timestamp.proto.
The Timestamp message represents a timestamp, an instant in time since the Unix epoch (January 1st, 1970).
Conversion to a Go Time ¶
The AsTime method can be used to convert a Timestamp message to a standard Go time.Time value in UTC:
t := ts.AsTime() ... // make use of t as a time.Time
Converting to a time.Time is a common operation so that the extensive set of time-based operations provided by the time package can be leveraged. See https://golang.org/pkg/time for more information.
The AsTime method performs the conversion on a best-effort basis. Timestamps with denormal values (e.g., nanoseconds beyond 0 and 99999999, inclusive) are normalized during the conversion to a time.Time. To manually check for invalid Timestamps per the documented limitations in timestamp.proto, additionally call the CheckValid method:
if err := ts.CheckValid(); err != nil { ... // handle error }
Conversion from a Go Time ¶
The timestamppb.New function can be used to construct a Timestamp message from a standard Go time.Time value:
ts := timestamppb.New(t) ... // make use of ts as a *timestamppb.Timestamp
In order to construct a Timestamp representing the current time, use Now:
ts := timestamppb.Now() ... // make use of ts as a *timestamppb.Timestamp
Index ¶
- Variables
- type Timestamp
- func (x *Timestamp) AsTime() time.Time
- func (x *Timestamp) CheckValid() error
- func (*Timestamp) Descriptor() ([]byte, []int)deprecated
- func (x *Timestamp) GetNanos() int32
- func (x *Timestamp) GetSeconds() int64
- func (x *Timestamp) IsValid() bool
- func (*Timestamp) ProtoMessage()
- func (x *Timestamp) ProtoReflect() protoreflect.Message
- func (x *Timestamp) Reset()
- func (x *Timestamp) String() string
Constants ¶
This section is empty.
Variables ¶
var File_aptos_util_timestamp_timestamp_proto protoreflect.FileDescriptor
Functions ¶
This section is empty.
Types ¶
type Timestamp ¶
type Timestamp struct { // Represents seconds of UTC time since Unix epoch // 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to // 9999-12-31T23:59:59Z inclusive. Seconds int64 `protobuf:"varint,1,opt,name=seconds,proto3" json:"seconds,omitempty"` // Non-negative fractions of a second at nanosecond resolution. Negative // second values with fractions must still have non-negative nanos values // that count forward in time. Must be from 0 to 999,999,999 // inclusive. Nanos int32 `protobuf:"varint,2,opt,name=nanos,proto3" json:"nanos,omitempty"` // contains filtered or unexported fields }
func (*Timestamp) CheckValid ¶
CheckValid returns an error if the timestamp is invalid. In particular, it checks whether the value represents a date that is in the range of 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive. An error is reported for a nil Timestamp.
func (*Timestamp) Descriptor
deprecated
func (*Timestamp) GetSeconds ¶
func (*Timestamp) IsValid ¶
IsValid reports whether the timestamp is valid. It is equivalent to CheckValid == nil.
func (*Timestamp) ProtoMessage ¶
func (*Timestamp) ProtoMessage()
func (*Timestamp) ProtoReflect ¶
func (x *Timestamp) ProtoReflect() protoreflect.Message