timestamp

package module
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2022 License: MIT Imports: 7 Imported by: 4

README

timestamp

Golang package for marshaling/unmarshaling UNIX timestamps to/from multiple formats such as JSON, Gob and BSON.

GoDoc

Build Status

Documentation

Overview

Package timestamp is used for marshaling/unmarshaling UNIX timestamps to/from JSON, GOB and BSON by implementing the appropriate interfaces for encoding/json, encoding/gob and labix.org/v2/mgo respectively.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Timestamp

type Timestamp time.Time

Timestamp is a named alias for time.Time, it represents a UNIX timestamp and provides functions for marshaling and unmarshaling both to/from JSON and to/from BSON

func Now

func Now() *Timestamp

Now returns a pointer to a Timestamp object with the current time, it is equal to creating a Timestamp object from time.Now()

func Time

func Time(t time.Time) *Timestamp

Time returns a pointer to a Timestamp object which is created from a time.Time object

func Unix

func Unix(sec, nsec int64) *Timestamp

Unix returns a pointer to a Timestamp object which is created from a UNIX timestamp

func (Timestamp) GetBSON

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

GetBSON defines how labix.org/v2/mgo marshals the object to BSON, the result is a time.Time object which is then handled by mgo

func (*Timestamp) GobDecode

func (t *Timestamp) GobDecode(data []byte) error

GobDecode decodes a Timestamp object from a byte slice and overwrites the receiver, it implements the GobDecoder interface GobDecode implements the gob.GobDecoder interface.

func (Timestamp) GobEncode

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

GobEncode returns a byte slice representing the encoding of the Timestamp object, it implements the GobEncoder interface

func (*Timestamp) IsEmpty added in v0.3.2

func (t *Timestamp) IsEmpty() bool

func (*Timestamp) MarshalBSONValue added in v0.2.0

func (t *Timestamp) MarshalBSONValue() (bsontype.Type, []byte, error)

func (Timestamp) MarshalJSON

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

MarshalJSON defines how encoding/json marshals the object to JSON, the result is a string of the UNIX timestamp

func (Timestamp) MarshalXML

func (t Timestamp) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML defines how encoding/xml marshals the object to XML, the result is a string of the UNIX timestamp

func (*Timestamp) SetBSON

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

SetBSON defines how labix.org/v2/mgo unmarshals the object from BSON, the raw BSON data is unmarshaled to a time.Time object which is used for the Timestamp object value

func (Timestamp) String

func (t Timestamp) String() string

String returns the string representation of the Timestamp object, it is equal to the time.Time string representation of the Timestamp object value

func (Timestamp) Time

func (t Timestamp) Time() time.Time

Time returns a time.Time object with the same time value as the Timestamp object

func (Timestamp) ToMili

func (t Timestamp) ToMili() int64

func (Timestamp) Unix

func (t Timestamp) Unix() int64

Unix calls the Unix() method of a time.Time object with the same time values as the timestamp object

func (*Timestamp) UnmarshalBSONValue added in v0.2.0

func (t *Timestamp) UnmarshalBSONValue(typ bsontype.Type, data []byte) error

func (*Timestamp) UnmarshalJSON

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

UnmarshalJSON defines how encoding/json unmarshals the object from JSON, a UNIX timestamp string is converted to int which is used for the Timestamp object value

func (*Timestamp) UnmarshalXML

func (t *Timestamp) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML defines how encoding/xml unmarshals the object from XML, a UNIX timestamp string is converted to int which is used for the Timestamp object value

Jump to

Keyboard shortcuts

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