Version: v0.0.0-...-c20f884 Latest Latest

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

Go to latest
Published: Jul 30, 2019 License: MIT Imports: 4 Imported by: 1



Package mtime extends the standard time package with extra functionality



This section is empty.


This section is empty.


This section is empty.


type Duration

type Duration struct {

Duration wraps time.Duration to implement marshaling and unmarshaling methods

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface, marshaling the Duration as a json string via Duration's String method

func (Duration) MarshalText

func (d Duration) MarshalText() ([]byte, error)

MarshalText implements the text.Marshaler interface

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface, unmarshaling the Duration as a JSON string and using the time.ParseDuration function on that

func (*Duration) UnmarshalText

func (d *Duration) UnmarshalText(b []byte) error

UnmarshalText implements the text.Unmarshaler interface

type TS

type TS struct {

TS 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 NewTS

func NewTS(t time.Time) TS

NewTS returns a new TS instance wrapping the given time.Time, which will possibly be truncated a certain amount to account for floating point precision.

func NowTS

func NowTS() TS

NowTS is a wrapper around time.Now which returns a TS.

func TSFromFloat64

func TSFromFloat64(ts float64) TS

TSFromFloat64 returns a TS 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 TSFromInt64

func TSFromInt64(ts int64) TS

TSFromInt64 returns a TS equal to the given int64, assuming it too is a unix timestamp

func TSFromString

func TSFromString(ts string) (TS, error)

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

func (TS) Float64

func (t TS) Float64() float64

Float64 returns the float representation of the timestamp in seconds.

func (TS) IsUnixZero

func (t TS) 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 (TS) MarshalJSON

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

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

func (TS) String

func (t TS) String() string

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

func (*TS) UnmarshalJSON

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

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

Jump to

Keyboard shortcuts

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