Skip to content

Commit f4b57b4

Browse files
Copilotshueybubbles
andcommitted
Fix bulkcopy support for nullable civil types by returning proper driver.Value types
Co-authored-by: shueybubbles <[email protected]>
1 parent 44f0939 commit f4b57b4

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

civil_null.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func (n NullDate) Value() (driver.Value, error) {
3939
if !n.Valid {
4040
return nil, nil
4141
}
42-
return n.Date, nil
42+
return n.Date.In(time.UTC), nil
4343
}
4444

4545
// String returns the string representation of the date or "NULL".
@@ -107,7 +107,7 @@ func (n NullDateTime) Value() (driver.Value, error) {
107107
if !n.Valid {
108108
return nil, nil
109109
}
110-
return n.DateTime, nil
110+
return n.DateTime.In(time.UTC), nil
111111
}
112112

113113
// String returns the string representation of the datetime or "NULL".
@@ -175,7 +175,7 @@ func (n NullTime) Value() (driver.Value, error) {
175175
if !n.Valid {
176176
return nil, nil
177177
}
178-
return n.Time, nil
178+
return time.Date(1, 1, 1, n.Time.Hour, n.Time.Minute, n.Time.Second, n.Time.Nanosecond, time.UTC), nil
179179
}
180180

181181
// String returns the string representation of the time or "NULL".

civil_null_test.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ func TestNullDate(t *testing.T) {
1919
if err != nil {
2020
t.Errorf("Unexpected error: %v", err)
2121
}
22-
if val != date {
23-
t.Errorf("Expected %v, got %v", date, val)
22+
expectedTime := date.In(time.UTC)
23+
if val != expectedTime {
24+
t.Errorf("Expected %v, got %v", expectedTime, val)
2425
}
2526

2627
// Invalid case
@@ -139,8 +140,9 @@ func TestNullDateTime(t *testing.T) {
139140
if err != nil {
140141
t.Errorf("Unexpected error: %v", err)
141142
}
142-
if val != dateTime {
143-
t.Errorf("Expected %v, got %v", dateTime, val)
143+
expectedTime := dateTime.In(time.UTC)
144+
if val != expectedTime {
145+
t.Errorf("Expected %v, got %v", expectedTime, val)
144146
}
145147

146148
// Invalid case
@@ -203,8 +205,9 @@ func TestNullTime(t *testing.T) {
203205
if err != nil {
204206
t.Errorf("Unexpected error: %v", err)
205207
}
206-
if val != civilTime {
207-
t.Errorf("Expected %v, got %v", civilTime, val)
208+
expectedTime := time.Date(1, 1, 1, civilTime.Hour, civilTime.Minute, civilTime.Second, civilTime.Nanosecond, time.UTC)
209+
if val != expectedTime {
210+
t.Errorf("Expected %v, got %v", expectedTime, val)
208211
}
209212

210213
// Invalid case

tvp_go19.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func (tvp TVP) encode(schema, name string, columnStr []columnStruct, tvpFieldInd
109109
if tvp.verifyStandardTypeOnNull(buf, tvpVal) {
110110
continue
111111
}
112-
112+
113113
// Extract inner value from nullable civil types when they are valid
114114
switch v := tvpVal.(type) {
115115
case NullDate:
@@ -125,7 +125,7 @@ func (tvp TVP) encode(schema, name string, columnStr []columnStruct, tvpFieldInd
125125
tvpVal = v.Time
126126
}
127127
}
128-
128+
129129
valOf := reflect.ValueOf(tvpVal)
130130
elemKind := field.Kind()
131131
if elemKind == reflect.Ptr && valOf.IsNil() {

0 commit comments

Comments
 (0)