Mercurial > gemma
diff pkg/soap/nts/service.go @ 3580:d38b20ccb6f9
GM import: Be more graceful when accepting measure/issue dates.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 03 Jun 2019 17:55:49 +0200 |
parents | 9ae43313b463 |
children | d4a8d084eab4 |
line wrap: on
line diff
--- a/pkg/soap/nts/service.go Mon Jun 03 17:21:18 2019 +0200 +++ b/pkg/soap/nts/service.go Mon Jun 03 17:55:49 2019 +0200 @@ -18,12 +18,29 @@ "encoding/xml" "time" + "gemma.intevation.de/gemma/pkg/misc" "gemma.intevation.de/gemma/pkg/soap" ) -// against "unused imports" -var _ time.Time -var _ xml.Name +var guessDateTime = misc.TimeGuesser([]string{ + "2006-01-02T15:04:05", + "2006-01-02T15:04:05-07:00", +}).Guess + +type DateTime struct{ time.Time } + +func (dt *DateTime) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { + var value string + if err := d.DecodeElement(&value, &start); err != nil { + return err + } + t, err := guessDateTime(value) + if err != nil { + return err + } + *dt = DateTime{t} + return nil +} type Message_type_type string @@ -124,7 +141,7 @@ } type Paging_result_type struct { - XMLName xml.Name `xml:"http://www.ris.eu/nts/4.0.4.0 paging_result"` + XMLName xml.Name `xml:"http://www.ris.eu/nts.ms/2.0.4.0 paging_result"` Offset *NonNegativeInteger `xml:"offset,omitempty"` @@ -1172,7 +1189,7 @@ District string `xml:"district,omitempty"` // Date and time of publication including time zone - Date_issue time.Time `xml:"date_issue,omitempty"` + Date_issue DateTime `xml:"date_issue,omitempty"` } type Ftm_type struct { @@ -1291,7 +1308,7 @@ Regime_code *Regime_code_enum `xml:"regime_code,omitempty"` // Date and Time of measurement or predicted value including time zone - Measuredate time.Time `xml:"measuredate,omitempty"` + Measuredate DateTime `xml:"measuredate,omitempty"` // Difference with comparative value Difference *Difference_type `xml:"difference,omitempty"` @@ -1330,7 +1347,7 @@ XMLName xml.Name `xml:"http://www.ris.eu/nts/4.0.4.0 ice_condition_type"` // Date and Time of measurement or prediction including time zone - Measuredate time.Time `xml:"measuredate,omitempty"` + Measuredate DateTime `xml:"measuredate,omitempty"` // Condition code Ice_condition_code *Ice_condition_code_enum `xml:"ice_condition_code,omitempty"` @@ -1375,7 +1392,7 @@ XMLName xml.Name `xml:"http://www.ris.eu/nts/4.0.4.0 weather_report_type"` // Date and time of measurement or predicted value including timezone - Measuredate time.Time `xml:"measuredate,omitempty"` + Measuredate DateTime `xml:"measuredate,omitempty"` // Forecast (true or 1) OR Actual report (false or 0) Forecast bool `xml:"forecast,omitempty"`