Skip to content

Commit

Permalink
Add missing time.Time type constraint for records and nodes/rels
Browse files Browse the repository at this point in the history
Fixes #486

Signed-off-by: Florent Biville <florent.biville@neo4j.com>
  • Loading branch information
robsdedude authored and fbiville committed May 17, 2023
1 parent 0f1f1e8 commit 0eccfa3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
3 changes: 2 additions & 1 deletion neo4j/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ package neo4j

import (
"fmt"
"time"
)

type PropertyValue interface {
bool | int64 | float64 | string |
Point2D | Point3D |
Date | LocalTime | LocalDateTime | Time | Duration | /* OffsetTime == Time == dbtype.Time */
Date | LocalTime | LocalDateTime | Time | Duration | time.Time | /* OffsetTime == Time == dbtype.Time */
[]byte | []any
}

Expand Down
9 changes: 9 additions & 0 deletions neo4j/graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,15 @@ func TestGetProperty(outer *testing.T) {
AssertNoError(t, err)
})

inner.Run("datetimes", func(t *testing.T) {
entity := test.make(singleProp("k", now))

prop, err := neo4j.GetProperty[time.Time](entity, "k")

AssertDeepEquals(t, prop, now)
AssertNoError(t, err)
})

inner.Run("durations", func(t *testing.T) {
entity := test.make(singleProp("k", neo4j.DurationOf(5, 4, 3, 2)))

Expand Down
7 changes: 5 additions & 2 deletions neo4j/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@

package neo4j

import "fmt"
import (
"fmt"
"time"
)

type RecordValue interface {
bool | int64 | float64 | string |
Point2D | Point3D |
Date | LocalTime | LocalDateTime | Time | Duration | /* OffsetTime == Time == dbtype.Time */
Date | LocalTime | LocalDateTime | Time | Duration | time.Time | /* OffsetTime == Time == dbtype.Time */
[]byte | []any | map[string]any |
Node | Relationship | Path
}
Expand Down
10 changes: 10 additions & 0 deletions neo4j/record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,16 @@ func TestGetRecordValue(outer *testing.T) {
AssertNoError(t, err)
})

inner.Run("datetimes", func(t *testing.T) {
entity := record("k", now)

value, isNil, err := neo4j.GetRecordValue[time.Time](entity, "k")

AssertDeepEquals(t, value, now)
AssertFalse(t, isNil)
AssertNoError(t, err)
})

inner.Run("durations", func(t *testing.T) {
entity := record("k", neo4j.DurationOf(5, 4, 3, 2))

Expand Down

0 comments on commit 0eccfa3

Please sign in to comment.