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 ¶
- func IsValidEpoch(epoch int64) bool
- type Timestamp
- func (t Timestamp) GetBSON() (interface{}, error)
- func (t *Timestamp) GobDecode(data []byte) error
- func (t Timestamp) GobEncode() ([]byte, error)
- func (t *Timestamp) IsEmpty() bool
- func (t *Timestamp) IsValid() bool
- func (t *Timestamp) MarshalBSONValue() (bsontype.Type, []byte, error)
- func (t Timestamp) MarshalJSON() ([]byte, error)
- func (t Timestamp) MarshalXML(e *xml.Encoder, start xml.StartElement) error
- func (t *Timestamp) SetBSON(raw bson.Raw) error
- func (t Timestamp) String() string
- func (t Timestamp) Time() time.Time
- func (t Timestamp) ToMili() int64
- func (t Timestamp) Unix() int64
- func (t *Timestamp) UnmarshalBSONValue(typ bsontype.Type, data []byte) error
- func (t *Timestamp) UnmarshalJSON(b []byte) error
- func (t *Timestamp) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsValidEpoch ¶ added in v0.3.4
Types ¶
type Timestamp ¶
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 (Timestamp) GetBSON ¶
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 ¶
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 ¶
GobEncode returns a byte slice representing the encoding of the Timestamp object, it implements the GobEncoder interface
func (*Timestamp) MarshalBSONValue ¶ added in v0.2.0
func (Timestamp) MarshalJSON ¶
func (Timestamp) MarshalXML ¶
MarshalXML defines how encoding/xml marshals the object to XML, the result is a string of the UNIX timestamp
func (*Timestamp) SetBSON ¶
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 ¶
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 ¶
Time returns a time.Time object with the same time value as the Timestamp object
func (Timestamp) Unix ¶
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 (*Timestamp) UnmarshalJSON ¶
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 ¶
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