Documentation ¶
Overview ¶
Package epoch contains primitives for marshaling/unmarshaling Unix timestamp/epoch to/from build-in time.Time type in JSON.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FloatMS ¶ added in v1.5.0
FloatMS - integer part of timestamp represents seconds and fractional - milliseconds since the Epoch(Unix time), e.g.
1136239445.999
Inherits built-in time.Time type, thus has all it methods, but has custom serializer and deserializer(converts float timestamp into built-in time.Time and vice versa).
func (FloatMS) MarshalJSON ¶ added in v1.5.0
MarshalJSON - implements JSON marshaling interface
func (*FloatMS) UnmarshalJSON ¶ added in v1.5.0
type Milliseconds ¶ added in v1.1.0
Milliseconds - same as epoch.Seconds, but for Epoch(Unix time) in milliseconds.
func NewMilliseconds ¶ added in v1.1.0
func NewMilliseconds(t time.Time) Milliseconds
NewMilliseconds - returns Milliseconds
func (Milliseconds) MarshalJSON ¶ added in v1.1.0
func (m Milliseconds) MarshalJSON() ([]byte, error)
MarshalJSON - implements JSON marshaling interface
func (*Milliseconds) UnmarshalJSON ¶ added in v1.1.0
func (m *Milliseconds) UnmarshalJSON(data []byte) error
UnmarshalJSON - implements JSON unmarshaling interface
type Seconds ¶
Seconds - seconds since the Epoch(Unix time). Inherits built-in time.Time type, thus has all it methods, but has custom serializer and deserializer(converts integer into built-in time.Time and vice versa).
Example ¶
package main import ( "encoding/json" "fmt" "github.com/vtopc/epoch" ) type Request struct { Timestamp epoch.Seconds `json:"timestamp"` } func main() { var v Request err := json.Unmarshal([]byte(`{"timestamp":1136239445}`), &v) if err != nil { panic(err) } // Also as epoch.Seconds inherits all time.Time's methods: fmt.Println(v.Timestamp.Year()) fmt.Println(v.Timestamp.UTC().String()) }
Output: 2006 2006-01-02 22:04:05 +0000 UTC
func (Seconds) MarshalJSON ¶
MarshalJSON - implements JSON marshaling interface
func (*Seconds) UnmarshalJSON ¶
UnmarshalJSON - implements JSON unmarshaling interface
type StrMilliseconds ¶ added in v1.2.0
StrMilliseconds - same as epoch.Milliseconds, but for strings.
func NewStrMilliseconds ¶ added in v1.2.0
func NewStrMilliseconds(t time.Time) StrMilliseconds
NewStrMilliseconds - returns Milliseconds
func (StrMilliseconds) MarshalJSON ¶ added in v1.2.0
func (m StrMilliseconds) MarshalJSON() ([]byte, error)
MarshalJSON - implements JSON marshaling interface
func (*StrMilliseconds) UnmarshalJSON ¶ added in v1.2.0
func (m *StrMilliseconds) UnmarshalJSON(data []byte) error
UnmarshalJSON - implements JSON unmarshaling interface
type StrSeconds ¶ added in v1.2.0
StrSeconds - seconds since the Epoch(Unix time) as string. Inherits built-in time.Time type, thus has all it methods, but has custom serializer and deserializer(converts integer into built-in time.Time and vice versa).
func NewStrSeconds ¶ added in v1.2.0
func NewStrSeconds(t time.Time) StrSeconds
NewStrSeconds - returns StrSeconds
func (StrSeconds) MarshalJSON ¶ added in v1.2.0
func (s StrSeconds) MarshalJSON() ([]byte, error)
MarshalJSON - implements JSON marshaling interface
func (*StrSeconds) UnmarshalJSON ¶ added in v1.2.0
func (s *StrSeconds) UnmarshalJSON(data []byte) error
UnmarshalJSON - implements JSON unmarshaling interface