Skip to content

Instantly share code, notes, and snippets.

@jordanorelli
Created April 24, 2012 19:19
Show Gist options
  • Save jordanorelli/2482869 to your computer and use it in GitHub Desktop.
Save jordanorelli/2482869 to your computer and use it in GitHub Desktop.
type Timestamp time.Time
func (t *Timestamp) UnmarshalJSON(b []byte) error {
i, err := strconv.ParseInt(string(b[1:len(b)-1]), 10, 0)
if err != nil {
log.Println("Unable to parse timestamp from json")
}
*t = Timestamp(time.Unix(i, 0))
return nil
}
func (t *Timestamp) GetBSON() (interface{}, error) {
return time.Time(*t), nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment