Skip to content

Commit

Permalink
add empty
Browse files Browse the repository at this point in the history
  • Loading branch information
acim committed Dec 2, 2022
1 parent 3174cd6 commit 07391e1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pgtype/range.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,10 @@ func (dst *Range[T]) UnmarshalJSON(b []byte) error {
Valid: true,
}

if dst.LowerType == Empty && dst.UpperType == Empty {
return nil
}

if err = json.Unmarshal([]byte(`"`+r.Lower+`"`), &dst.Lower); err != nil {
return err
}
Expand Down
5 changes: 5 additions & 0 deletions pgtype/range_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,11 @@ func TestRangeDateUnmarshalJSON(t *testing.T) {
result Range[Date]
}{
{src: "null", result: Range[Date]{}},
{src: `"empty"`, result: Range[Date]{
LowerType: Empty,
UpperType: Empty,
Valid: true,
}},
{src: `"(2022-12-01,2022-12-31)"`, result: Range[Date]{
Lower: Date{Time: time.Date(2022, 12, 1, 0, 0, 0, 0, time.UTC), Valid: true},
Upper: Date{Time: time.Date(2022, 12, 31, 0, 0, 0, 0, time.UTC), Valid: true},
Expand Down

0 comments on commit 07391e1

Please sign in to comment.