Skip to content

Write time.Time results as DateTime fields in the spatial writer - #152

Merged
HenryGeorgist merged 1 commit into
mainfrom
fix/spatialwriter-datetime
Sep 23, 2026
Merged

HenryGeorgist merged 1 commit into
mainfrom
fix/spatialwriter-datetime

Conversation

@trietmnj

Copy link
Copy Markdown
Contributor
  • Problem: the spatial writer never writes time.Time values. time.Time has reflect kind Struct, which gdalTypes does not map, so the field is created with GDAL's zero type (Integer), and the value switch has no case for it. The lifecycle completion_date column is null in every row (all 437,893 event rows of a DE001 run).
  • Fix: create the field as FT_DateTime when the value is a time.Time, and write it with SetFieldDateTime; a zero time stays null. New spatialwriter_test.go writes a GeoPackage and reads the date back.
resultswriters/spatialwriter.go                     completion_date = 2040-11-05 04:17 (time.Time)

 FIRST ROW — create fields
   :74   atype := reflect.TypeOf(result[i])          → Kind() = Struct
   :81   gdaltype := gdalTypes[gotype]               utils.go:11 maps Float32/64, Int32, String only
                                                     → missing key → zero value = FT_Integer
         before:  field "completion"  Integer        ✗
   :82   this PR: time.Time → FT_DateTime            ✓

 EVERY ROW — set values
   :156  switch valType { String, Float32, Float64, Int32, Uint8 }
         before:  Struct falls through, nothing set  ✗  → null
   :171  this PR: case reflect.Struct
   :173           SetFieldDateTime(idx, t)            ✓  (zero time left null)

time.Time has reflect kind Struct, which gdalTypes does not map, so the field was created as Integer and the value switch skipped it: completion_date was never written. Create the field as DateTime and set it with SetFieldDateTime; a zero time stays null.
@HenryGeorgist
HenryGeorgist self-requested a review September 23, 2026 20:32
@trietmnj
trietmnj marked this pull request as ready for review September 23, 2026 20:37
"github.com/dewberry/gdal"
)

func TestSpatialResultsWriterWritesDateTime(t *testing.T) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for adding the test.

@HenryGeorgist
HenryGeorgist merged commit 5221190 into main Sep 23, 2026
1 check passed
@HenryGeorgist
HenryGeorgist deleted the fix/spatialwriter-datetime branch September 23, 2026 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants