@@ -111,6 +111,8 @@ type Date struct {
111
111
var (
112
112
_ xml.Unmarshaler = (* Date )(nil )
113
113
_ xml.UnmarshalerAttr = (* Date )(nil )
114
+
115
+ emptyValue = (time.Time {}).Add (1 )
114
116
)
115
117
116
118
// UnmarshalXML implements xml.Unmarshaler.
@@ -126,10 +128,17 @@ func (d *Date) UnmarshalXML(dec *xml.Decoder, start xml.StartElement) error {
126
128
if err := dec .DecodeElement (& s , & start ); err != nil {
127
129
return err
128
130
}
129
- // If the date is set but an empty string is the inner element, then the
130
- // date was set by an attr.
131
- if s == "" && ! d .Date .IsZero () {
131
+ switch {
132
+ case d .Date .Equal (emptyValue ):
133
+ // If we set the date to this sentinel value, then this element is
134
+ // pointless but we need to not return an error.
135
+ d .Date = time.Time {}
136
+ return nil
137
+ case s == "" && ! d .Date .IsZero ():
138
+ // If the date is set but an empty string is the inner element, then the
139
+ // date was set by an attr.
132
140
return nil
141
+ default :
133
142
}
134
143
var err error
135
144
// Try a variety of formats, because everything is terrible.
@@ -156,6 +165,12 @@ func (d *Date) UnmarshalXMLAttr(attr xml.Attr) error {
156
165
if attr .Name .Local != name .Local {
157
166
return xml .UnmarshalError (fmt .Sprintf ("unexpected attr : %v" , attr ))
158
167
}
168
+ // We want to allow for an empty value, because some vendors can't be
169
+ // bothered to remove empty entities from their database.
170
+ if attr .Value == "" {
171
+ d .Date = emptyValue
172
+ return nil
173
+ }
159
174
var err error
160
175
d .Date , err = time .Parse (dsfmt , attr .Value )
161
176
if err != nil {
0 commit comments