-
Notifications
You must be signed in to change notification settings - Fork 17
/
time.go
24 lines (21 loc) · 647 Bytes
/
time.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package epp
import (
"encoding/xml"
"time"
)
// Time represents EPP date-time values, serialized to XML in RFC-3339 format.
// Because the default encoding.TextMarshaler implementation in time.Time uses
// RFC-3339, we don’t need to create a custom marshaler for this type.
type Time struct {
time.Time
}
// UnmarshalXML implements a custom XML unmarshaler that ignores time parsing errors.
// http://stackoverflow.com/a/25015260
func (t *Time) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
var v string
d.DecodeElement(&v, &start)
if tt, err := time.Parse(time.RFC3339, v); err == nil {
*t = Time{tt}
}
return nil
}