1
0
mirror of https://github.com/aclindsa/ofxgo.git synced 2025-07-01 11:48:38 -04:00

types: Be more lenient on Date, Int, and Amount parsing

Some of these types can have stray newlines in them, and Vanguard has a
very strange bug where they repeat the time portion of a DTSTART element
for a second time (we disregard the latter portion).
This commit is contained in:
2017-03-19 20:46:01 -04:00
parent bd10b644a9
commit 81814feaff
2 changed files with 66 additions and 20 deletions

View File

@ -14,6 +14,25 @@ import (
type Int int64
func (i *Int) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
var value string
err := d.DecodeElement(&value, &start)
if err != nil {
return err
}
value = strings.TrimSpace(value)
i2, err := strconv.ParseInt(value, 10, 64)
if err != nil {
return err
}
*i = Int(i2)
return nil
}
type Amount big.Rat
func (a *Amount) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
@ -25,6 +44,8 @@ func (a *Amount) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
return err
}
value = strings.TrimSpace(value)
// The OFX spec allows the start of the fractional amount to be delineated
// by a comma, so fix that up before attempting to parse it into big.Rat
value = strings.Replace(value, ",", ".", 1)
@ -63,6 +84,9 @@ func (od *Date) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
return err
}
value = strings.SplitN(value, "]", 2)[0]
value = strings.TrimSpace(value)
// Split the time zone off, if any
split := strings.SplitN(value, "[", 2)
if len(split) == 2 {