mediocre-go-lib: Index | Files

package mtime

import ""

Package mtime extends the standard time package with extra functionality


Package Files

dur.go mtime.go ts.go

type Duration Uses

type Duration struct {

Duration wraps time.Duration to implement marshaling and unmarshaling methods

func (Duration) MarshalJSON Uses

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 Uses

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

MarshalText implements the text.Marshaler interface

func (*Duration) UnmarshalJSON Uses

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 Uses

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

UnmarshalText implements the text.Unmarshaler interface

type TS Uses

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 Uses

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 Uses

func NowTS() TS

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

func TSFromFloat64 Uses

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 Uses

func TSFromInt64(ts int64) TS

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

func TSFromString Uses

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 Uses

func (t TS) Float64() float64

Float64 returns the float representation of the timestamp in seconds.

func (TS) IsUnixZero Uses

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 Uses

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 Uses

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 Uses

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

Package mtime imports 4 packages (graph) and is imported by 2 packages. Updated 2018-08-10. Refresh now. Tools for package owners.