Skip to content

Instantly share code, notes, and snippets.

@msingle
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msingle/bdc07a8bb9c211fcf4e9 to your computer and use it in GitHub Desktop.
Save msingle/bdc07a8bb9c211fcf4e9 to your computer and use it in GitHub Desktop.
const longform string = "2006-01-02T15:04:00"
type WrapTime struct{
time.Time
}
func (t WrapTime) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
fmted := t.Format(longform)
err := e.EncodeElement(fmted, start)
if err != nil {
return err
}
return nil
}
func (t *WrapTime) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
var v string
d.DecodeElement(&v, &start)
parse, err := time.Parse(longform, v)
if err != nil {
return err
}
*t = WrapTime{parse}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment