golib: github.com/levenlabs/golib/timeutil Index | Files

package timeutil

import "github.com/levenlabs/golib/timeutil"

Package timeutil contains functions and types which aid in dealing with time


Package Files

doc.go timestamp.go

type Timestamp Uses

type Timestamp struct {

Timestamp is a wrapper around time.Time which adds methods to marshal and unmarshal the value as a unix timestamp instead of a formatted string

func TimestampFromFloat64 Uses

func TimestampFromFloat64(ts float64) Timestamp

TimestampFromFloat64 returns a Timestamp equal to the given float64, assuming it too is a unix timestamp. The float64 is interpreted as number of seconds, with everything after the decimal indicating milliseconds, microseconds, and nanoseconds

func TimestampFromInt64 Uses

func TimestampFromInt64(ts int64) Timestamp

TimestampFromInt64 returns a Timestamp equal to the given int64, assuming it too is a unix timestamp

func TimestampFromString Uses

func TimestampFromString(ts string) (Timestamp, error)

TimestampFromString attempts to parse the string as a float64, and then passes that into TimestampFromFloat64, returning the result

func TimestampNow Uses

func TimestampNow() Timestamp

TimestampNow is simply a wrapper around time.Now which returns a Timestamp.

func (Timestamp) Float64 Uses

func (t Timestamp) Float64() float64

Float64 returns the float representation of the timestamp in seconds.

func (Timestamp) GetBSON Uses

func (t Timestamp) GetBSON() (interface{}, error)

GetBSON implements the bson.Getter interface

func (Timestamp) IsUnixZero Uses

func (t Timestamp) IsUnixZero() bool

IsUnixZero returns true if the timestamp is equal to the unix zero timestamp, representing 1/1/1970. This is different than checking if the timestamp is the empty value (which should be done with IsZero)

func (Timestamp) MarshalJSON Uses

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

MarshalJSON returns the JSON representation of the Timestamp as an integer. It never returns an error

func (*Timestamp) SetBSON Uses

func (t *Timestamp) SetBSON(raw bson.Raw) error

SetBSON implements the bson.Setter interface

func (Timestamp) String Uses

func (t Timestamp) String() string

String returns the string representation of the Timestamp, in the form of a floating point form of the time as a unix timestamp

func (*Timestamp) UnmarshalJSON Uses

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

UnmarshalJSON takes a JSON integer and converts it into a Timestamp, or returns an error if this can't be done

Package timeutil imports 4 packages (graph) and is imported by 4 packages. Updated 2019-05-12. Refresh now. Tools for package owners.