timestamp

package module
v0.10.3 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: MIT Imports: 10 Imported by: 2

README

Timestamp

Standard cross-language timestamp object.

Introduction

This is a simple protobuf encoding for timestamps.

Note: in most cases you will want to use the built-in Protobuf timestamp. This is just a helpful implementation for those cases where a simpler uint64 millisecond representation makes more sense.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyTimestamp = errors.New("timestamp is empty")

ErrEmptyTimestamp is returned if the timestamp was empty.

Functions

func ToTime

func ToTime(t uint64) time.Time

ToTime generates a time object from a millisecond timestamp.

func ToUnixMs added in v0.7.0

func ToUnixMs(t time.Time) uint64

ToUnixMs converts a time to unix ms.

Types

type Timestamp

type Timestamp struct {

	// TimeUnixMs timestamp in unix milliseconds.
	TimeUnixMs uint64 `protobuf:"varint,1,opt,name=time_unix_ms,json=timeUnixMs,proto3" json:"timeUnixMs,omitempty"`
	// contains filtered or unexported fields
}

Timestamp contains a cross-platform timestamp. protobuf-go-lite:disable-json

func Now

func Now() *Timestamp

Now returns a timestamp for now.

func ToTimestamp

func ToTimestamp(t time.Time) *Timestamp

ToTimestamp generates a millisecond timestamp from the time object.

func (*Timestamp) Clone added in v0.4.0

func (t *Timestamp) Clone() *Timestamp

Clone copies the timestamp.

func (*Timestamp) CloneMessageVT added in v0.7.0

func (m *Timestamp) CloneMessageVT() protobuf_go_lite.CloneMessage

func (*Timestamp) CloneVT added in v0.7.0

func (m *Timestamp) CloneVT() *Timestamp

func (*Timestamp) EqualMessageVT added in v0.7.0

func (this *Timestamp) EqualMessageVT(thatMsg any) bool

func (*Timestamp) EqualVT added in v0.6.0

func (this *Timestamp) EqualVT(that *Timestamp) bool

func (*Timestamp) Equals added in v0.4.0

func (t *Timestamp) Equals(ot *Timestamp) bool

Equals checks if the timestamp equals another timestamp.

func (*Timestamp) Format added in v0.7.2

func (t *Timestamp) Format(formatStr string) string

Format formats using time.Format.

func (*Timestamp) GetEmpty added in v0.7.1

func (t *Timestamp) GetEmpty() bool

GetEmpty checks if the timestamp is empty.

func (*Timestamp) GetTimeUnixMs

func (x *Timestamp) GetTimeUnixMs() uint64

func (*Timestamp) MarshalJSON added in v0.7.0

func (t *Timestamp) MarshalJSON() ([]byte, error)

MarshalJSON marshals the Timestamp to JSON.

func (*Timestamp) MarshalProtoJSON added in v0.9.0

func (t *Timestamp) MarshalProtoJSON(s *json.MarshalState)

MarshalProtoJSON marshals the Timestamp message to JSON.

func (*Timestamp) MarshalProtoText added in v0.8.3

func (x *Timestamp) MarshalProtoText() string

func (*Timestamp) MarshalToSizedBufferVT added in v0.5.1

func (m *Timestamp) MarshalToSizedBufferVT(dAtA []byte) (int, error)

func (*Timestamp) MarshalToVT added in v0.5.1

func (m *Timestamp) MarshalToVT(dAtA []byte) (int, error)

func (*Timestamp) MarshalVT added in v0.5.1

func (m *Timestamp) MarshalVT() (dAtA []byte, err error)

func (*Timestamp) ProtoMessage

func (*Timestamp) ProtoMessage()

func (*Timestamp) Reset

func (x *Timestamp) Reset()

func (*Timestamp) SizeVT added in v0.5.1

func (m *Timestamp) SizeVT() (n int)

func (*Timestamp) String

func (x *Timestamp) String() string

func (*Timestamp) ToRFC3339 added in v0.7.2

func (t *Timestamp) ToRFC3339() string

ToRFC3339 formats the timestamp as RFC3339

func (*Timestamp) ToTime

func (t *Timestamp) ToTime() time.Time

ToTime converts the Timestamp to a time.Time

func (*Timestamp) UnmarshalJSON added in v0.7.0

func (t *Timestamp) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals the Timestamp from JSON.

func (*Timestamp) UnmarshalProtoJSON added in v0.9.0

func (t *Timestamp) UnmarshalProtoJSON(s *json.UnmarshalState)

UnmarshalProtoJSON unmarshals the Timestamp message from JSON.

Supports string (unix milliseconds large value or RFC3339 timestamp), number (unix milliseconds)

func (*Timestamp) UnmarshalVT added in v0.5.1

func (m *Timestamp) UnmarshalVT(dAtA []byte) error

func (*Timestamp) Validate

func (t *Timestamp) Validate(allowEmpty bool) error

Validate checks the timestamp.

Jump to

Keyboard shortcuts

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