date format: cannot unmarshal into soap.XSDDate
giuliohome opened this issue · 0 comments
giuliohome commented
I have seen "Date/time types fail to unmarshal" issue #38 and "Xsd date and time support" PR #195
I have noticed xsd:date
Datatype Reference https://books.xmlschemata.org/relaxng/ch19-77041.html
[-]CCYY-MM-DD[Z|(+|-)hh:mm]
Note the Example where it is clearly stated that
Valid values include: 2001-10-26,...
I think that the case of a xsd:date like "2023-10-11" - i.e. without the optional T time part - is not covered by the current implementation.
Maybe that's a bug that could be fixed.
Indeed, given a generated struct attribute
SchemaRevisionDate soap.XSDDate `xml:"schemaRevisionDate,attr,omitempty" json:"schemaRevisionDate,omitempty"
I was getting the error:
could't get change request: cannot unmarshal into soap.XSDDate
Meanwhile I've worked it around by defining
type customDate struct {
t time.Time
}
func (c *customDate) UnmarshalXMLAttr(attr xml.Attr) error {
const myFormat = "2006-01-02"
parse, err := time.Parse(myFormat, attr.Value)
if err != nil {
return err
}
c.t = parse
return nil
}