changeset 1940:e6d851f53c99

Fairway dimension import: Made date parsing more tolerant.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 21 Jan 2019 15:46:54 +0100
parents 148917b4f859
children d4249b07e719
files pkg/imports/fd.go
diffstat 1 files changed, 16 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/imports/fd.go	Mon Jan 21 15:19:13 2019 +0100
+++ b/pkg/imports/fd.go	Mon Jan 21 15:46:54 2019 +0100
@@ -23,6 +23,7 @@
 	"time"
 
 	"gemma.intevation.de/gemma/pkg/common"
+	"gemma.intevation.de/gemma/pkg/misc"
 	"gemma.intevation.de/gemma/pkg/wfs"
 )
 
@@ -44,12 +45,18 @@
 
 type fdTime struct{ time.Time }
 
+var guessFDTime = misc.TimeGuesser([]string{
+	"20060102",
+	"2006",
+	"",
+}).Guess
+
 func (fdt *fdTime) UnmarshalJSON(data []byte) error {
 	var s string
 	if err := json.Unmarshal(data, &s); err != nil {
 		return err
 	}
-	t, err := time.Parse("20060102", s)
+	t, err := guessFDTime(s)
 	if err == nil {
 		*fdt = fdTime{t}
 	}
@@ -101,7 +108,7 @@
 func (*FairwayDimension) CleanUp() error { return nil }
 
 type fairwayDimensionProperties struct {
-	HydroSorDat fdTime `json:"hydro_sordat"`
+	HydroSorDat *fdTime `json:"hydro_sordat"`
 }
 
 type fdSummary struct {
@@ -252,6 +259,12 @@
 				badProperties++
 				continue
 			}
+			var dateInfo time.Time
+			if props.HydroSorDat == nil || props.HydroSorDat.IsZero() {
+				dateInfo = start
+			} else {
+				dateInfo = (*props.HydroSorDat).Time
+			}
 			switch feature.Geometry.Type {
 			case "Polygon":
 				var p polygonSlice
@@ -268,7 +281,7 @@
 					fd.MinWidth,
 					fd.MaxWidth,
 					fd.Depth,
-					props.HydroSorDat.Time,
+					dateInfo,
 					fd.SourceOrganization,
 				).Scan(&fdid, &lat, &lon)
 				switch {