pbtimestamp

package
v0.0.0-...-63a4b02 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 28, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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 New

func New(t time.Time) *Timestamp

New constructs a new Timestamp from the provided time.Time.

func Now

func Now() *Timestamp

Now constructs a new Timestamp from the current time.

func (*Timestamp) AsTime

func (x *Timestamp) AsTime() time.Time

AsTime converts x to a time.Time.

func (*Timestamp) CheckValid

func (x *Timestamp) CheckValid() error

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) Descriptor() ([]byte, []int)

Deprecated: Use Timestamp.ProtoReflect.Descriptor instead.

func (*Timestamp) GetNanos

func (x *Timestamp) GetNanos() int32

func (*Timestamp) GetSeconds

func (x *Timestamp) GetSeconds() int64

func (*Timestamp) IsValid

func (x *Timestamp) IsValid() bool

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

func (*Timestamp) Reset

func (x *Timestamp) Reset()

func (*Timestamp) String

func (x *Timestamp) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL