Skip to content

Conversation

@MuhammadQadora
Copy link

@MuhammadQadora MuhammadQadora commented Jul 9, 2025

fix #32

Summary by CodeRabbit

  • New Features

    • Support for returning temporal and duration types (date, time, datetime, duration) from graph queries.
  • Tests

    • Added tests validating parsing and retrieval of temporal and duration values as native Go time and duration objects.
  • Refactor

    • Renamed example public identifiers for clearer naming.
  • Chores

    • Added a development history directory to the ignore list.

@MuhammadQadora MuhammadQadora requested review from AviAvni and barakb July 9, 2025 08:16
@MuhammadQadora MuhammadQadora linked an issue Jul 9, 2025 that may be closed by this pull request
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 9, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Adds parsing support for four temporal scalar types (time, date, datetime, duration) in query result parsing, introduces four tests verifying returned temporal/duration values, renames two exported example test functions, and updates .gitignore to ignore .history/.

Changes

Cohort / File(s) Change Summary
Tests
client_test.go
Added tests TestGetTime, TestGetDate, TestGetDateTime, TestGetDuration that execute Cypher queries returning temporal/duration scalars and assert parsed time.Time / time.Duration values and components.
Result parsing
query_result.go
Added scalar constants VALUE_DATETIME, VALUE_DATE, VALUE_TIME, VALUE_DURATION; imported time; extended QueryResult.parseScalar to convert scalar payloads into time.Time (using Unix/UnixMilli) and time.Duration (seconds).
Examples / public symbol rename
example_graph_test.go
Renamed exported example functions: ExampleSelectGraphExampleFalkorDB_SelectGraph, ExampleGraphNew_tlsExampleFalkorDBNew_tls (no behavior change).
Repository metadata
.gitignore
Added .history/ to ignore list (minor ordering/newline change).

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant Test as Tests (client_test.go)
    participant Client as Go Client
    participant Parser as QueryResult.parseScalar
    participant DB as FalkorDB Server

    Note over Test,Client: Test issues Cypher query returning temporal/duration scalar
    Test->>Client: Execute query
    Client->>DB: Send query
    DB-->>Client: ResultSet (type tag + int64 payload)
    Client->>Parser: parseScalar(cell)
    alt VALUE_TIME / VALUE_DATE / VALUE_DATETIME
        Parser-->>Parser: convert int64 -> time.Time (Unix / UnixMilli)
    else VALUE_DURATION
        Parser-->>Parser: convert int64 -> time.Duration (seconds)
    end
    Parser-->>Client: parsed value
    Client-->>Test: Return record with parsed temporal/duration value
    Test->>Test: Assert types/components
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

In a burrow of bytes I hop and rhyme,
I stitched the clocks and nudged the time.
Seconds, days, and years align,
Tests now prove each gentle sign.
🐇🕰️ — a rabbit's small commit of time.

Pre-merge checks (2 passed, 3 warnings)

❌ Failed checks (3 warnings)
Check name Status Explanation Resolution
Linked Issues Check ⚠️ Warning The pull request successfully adds parsing logic for Date, DateTime, Time, and Duration scalar types and includes corresponding tests to verify deserialization of temporal values, but it does not implement the complementary serialization support for sending time-related parameters back to the server as required by issue #32. Extend the client’s parameter serialization layer to accept and correctly encode Go’s time.Time and time.Duration values when constructing queries so that both serialization and deserialization of temporal types are fully supported as specified.
Out of Scope Changes Check ⚠️ Warning The renaming of example functions in example_graph_test.go and the addition of .history/ to .gitignore do not relate to the implementation or testing of date/time support outlined in issue #32 and thus fall outside the defined objectives. Remove or extract the example function rename and .gitignore modifications into a separate pull request so that this PR remains focused solely on temporal type support in the Go client.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly captures the primary work of the changeset by highlighting both the addition of time-related tests and the enhancement of query result handling for date/time values, which aligns clearly with the main PR objective of supporting temporal types in the client.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7db0a62 and 8d39a9c.

📒 Files selected for processing (1)
  • client_test.go (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
client_test.go (1)
record.go (1)
  • Record (3-6)
🔇 Additional comments (1)
client_test.go (1)

6-6: LGTM: import time is required by new tests.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 32-add-support-for-date-time-and-datetime-in-the-go-client

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@barakb barakb requested a review from Copilot July 9, 2025 08:21
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c31628f and 7e49f57.

📒 Files selected for processing (2)
  • client_test.go (2 hunks)
  • query_result.go (3 hunks)
🧰 Additional context used
🪛 GitHub Actions: Go
client_test.go

[error] 315-317: TestGetTime failed due to panic: runtime error: invalid memory address or nil pointer dereference. Occurred in github.com/FalkorDB/falkordb-go.TestGetTime at client_test.go:317.

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (go)
🔇 Additional comments (3)
query_result.go (2)

9-9: Good addition of time import for temporal data support.

The import is necessary for the new temporal data parsing functionality.


348-355: Critical: Confirm and adjust temporal data parsing (DATE, DATETIME, TIME)
The client currently assumes DATE and DATETIME are encoded as seconds since the Unix epoch and TIME as milliseconds since the epoch. There’s no evidence in the codebase or comments to back up these units or semantics. If TIME represents a time-of-day-only value (e.g., milliseconds since midnight), the existing conversion will yield an incorrect full‐date timestamp. Please verify the server’s encoding and update the conversions accordingly.

• File: query_result.go, lines 348–355

Suggested diff template:

 case VALUE_TIME:
-   return time.UnixMilli(v.(int64)), nil
+   // TODO: confirm TIME encoding (e.g., ms since midnight vs. epoch ms)
+   // If TIME is a time-of-day, convert v.(int64) into hours/minutes/seconds only:
+   //   ms := v.(int64)
+   //   h := ms / 3_600_000
+   //   m := (ms % 3_600_000) / 60_000
+   //   s := (ms % 60_000) / 1_000
+   //   ns := (ms % 1_000) * int64(time.Millisecond)
+   //   return time.Date(0, 1, 1, int(h), int(m), int(s), int(ns), time.UTC), nil
+   return time.UnixMilli(v.(int64)), nil
client_test.go (1)

6-6: Good addition of time import for temporal tests.

The import is necessary for the new temporal data type testing.

Comment on lines +335 to +345
func TestGetDateTime(t *testing.T) {
q := "RETURN localdatetime({year : 1984}) as date"
res, err := graph.Query(q, nil, nil)
if err != nil {
t.Error(err)
}
res.Next()
r := res.Record()
dateTimeValue := r.GetByIndex(0).(time.Time)
assert.Equal(t, dateTimeValue.Year(), 1984, "Unexpected DateTime value")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add error handling and improve test robustness.

This test also needs proper error handling. Additionally, consider adding type assertion safety checks.

Apply this diff:

 func TestGetDateTime(t *testing.T) {
     q := "RETURN localdatetime({year : 1984}) as date"
     res, err := graph.Query(q, nil, nil)
     if err != nil {
         t.Error(err)
+        return
     }
+    if res == nil {
+        t.Error("Query result is nil")
+        return
+    }
     res.Next()
     r := res.Record()
-    dateTimeValue := r.GetByIndex(0).(time.Time)
+    val := r.GetByIndex(0)
+    dateTimeValue, ok := val.(time.Time)
+    if !ok {
+        t.Errorf("Expected time.Time, got %T", val)
+        return
+    }
     assert.Equal(t, dateTimeValue.Year(), 1984, "Unexpected DateTime value")
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func TestGetDateTime(t *testing.T) {
q := "RETURN localdatetime({year : 1984}) as date"
res, err := graph.Query(q, nil, nil)
if err != nil {
t.Error(err)
}
res.Next()
r := res.Record()
dateTimeValue := r.GetByIndex(0).(time.Time)
assert.Equal(t, dateTimeValue.Year(), 1984, "Unexpected DateTime value")
}
func TestGetDateTime(t *testing.T) {
q := "RETURN localdatetime({year : 1984}) as date"
res, err := graph.Query(q, nil, nil)
if err != nil {
t.Error(err)
return
}
if res == nil {
t.Error("Query result is nil")
return
}
res.Next()
r := res.Record()
val := r.GetByIndex(0)
dateTimeValue, ok := val.(time.Time)
if !ok {
t.Errorf("Expected time.Time, got %T", val)
return
}
assert.Equal(t, dateTimeValue.Year(), 1984, "Unexpected DateTime value")
}
🤖 Prompt for AI Agents
In client_test.go around lines 335 to 345, the test lacks error handling after
calling res.Next() and does not safely assert the type of the returned value.
Add a check for the boolean result of res.Next() to handle the case where no
record is returned, and verify the type assertion for r.GetByIndex(0) before
using it as time.Time. If the type assertion fails, report an error in the test.
This will make the test more robust and prevent panics.

Comment on lines 323 to 333
func TestGetDate(t *testing.T) {
q := "RETURN date({year : 1984}) as date"
res, err := graph.Query(q, nil, nil)
if err != nil {
t.Error(err)
}
res.Next()
r := res.Record()
dateValue := r.GetByIndex(0).(time.Time)
assert.Equal(t, dateValue.Year(), 1984, "Unexpected Date value")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add error handling to prevent nil pointer dereference.

Similar to TestGetTime, this test needs proper error handling to prevent nil pointer dereference.

Apply this diff:

 func TestGetDate(t *testing.T) {
     q := "RETURN date({year : 1984}) as date"
     res, err := graph.Query(q, nil, nil)
     if err != nil {
         t.Error(err)
+        return
     }
+    if res == nil {
+        t.Error("Query result is nil")
+        return
+    }
     res.Next()
     r := res.Record()
     dateValue := r.GetByIndex(0).(time.Time)
     assert.Equal(t, dateValue.Year(), 1984, "Unexpected Date value")
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func TestGetDate(t *testing.T) {
q := "RETURN date({year : 1984}) as date"
res, err := graph.Query(q, nil, nil)
if err != nil {
t.Error(err)
}
res.Next()
r := res.Record()
dateValue := r.GetByIndex(0).(time.Time)
assert.Equal(t, dateValue.Year(), 1984, "Unexpected Date value")
}
func TestGetDate(t *testing.T) {
q := "RETURN date({year : 1984}) as date"
res, err := graph.Query(q, nil, nil)
if err != nil {
t.Error(err)
return
}
if res == nil {
t.Error("Query result is nil")
return
}
res.Next()
r := res.Record()
dateValue := r.GetByIndex(0).(time.Time)
assert.Equal(t, dateValue.Year(), 1984, "Unexpected Date value")
}
🤖 Prompt for AI Agents
In client_test.go around lines 323 to 333, the test lacks error handling after
calling res.Next(), which can cause a nil pointer dereference if no record is
returned. Add a check for the boolean result of res.Next() and handle the case
where it returns false by calling t.Error with an appropriate message and
returning early from the test. This ensures the test safely handles empty
results before accessing the record.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR extends query result handling by adding support for temporal data types (date, time, and datetime) and adds corresponding tests.

  • Added new constants and parsing logic in parseScalar for date, time, and datetime.
  • Introduced tests (TestGetTime, TestGetDate, TestGetDateTime) to verify correct handling of temporal values.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
query_result.go Added VALUE_DATETIME, VALUE_DATE, VALUE_TIME constants and parsing cases for each type.
client_test.go Added tests to assert correct extraction of time, date, and datetime from query results.
Comments suppressed due to low confidence (2)

client_test.go:336

  • [nitpick] The alias as date is confusing in the datetime test. Consider using as datetime to clearly reflect the returned type.
	q := "RETURN localdatetime({year : 1984}) as date"

client_test.go:320

  • [nitpick] The TestGetTime only checks the hour component. Consider adding assertions for minutes, seconds, and timezone to fully validate the time.Time value.
	assert.Equal(t, timeValue.Hour(), 12, "Unexpected Time value")

query_result.go Outdated
VALUE_MAP
VALUE_POINT
VALUE_VECTORF32
VALUE_DATETIME // Deprecated, use VALUE_POINT instead
Copy link

Copilot AI Jul 9, 2025

Choose a reason for hiding this comment

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

[nitpick] The VALUE_DATETIME constant is marked deprecated but is still actively parsed. Consider removing it or updating the comment to reflect current usage or migration plan.

Suggested change
VALUE_DATETIME // Deprecated, use VALUE_POINT instead
VALUE_DATETIME // Deprecated: Retained for backward compatibility. Migrate to VALUE_POINT where possible.

Copilot uses AI. Check for mistakes.
Comment on lines +349 to +355
return time.Unix(v.(int64), 0), nil

case VALUE_DATE:
return time.Unix(v.(int64), 0), nil

case VALUE_TIME:
return time.UnixMilli(v.(int64)), nil
Copy link

Copilot AI Jul 9, 2025

Choose a reason for hiding this comment

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

Directly asserting v.(int64) may panic if the stored value isn’t an int64. Use a safe type check (t, ok := v.(int64)) and return an error if the assertion fails.

Suggested change
return time.Unix(v.(int64), 0), nil
case VALUE_DATE:
return time.Unix(v.(int64), 0), nil
case VALUE_TIME:
return time.UnixMilli(v.(int64)), nil
timestamp, ok := v.(int64)
if !ok {
return nil, errors.New("expected int64 for VALUE_DATETIME")
}
return time.Unix(timestamp, 0), nil
case VALUE_DATE:
timestamp, ok := v.(int64)
if !ok {
return nil, errors.New("expected int64 for VALUE_DATE")
}
return time.Unix(timestamp, 0), nil
case VALUE_TIME:
timestamp, ok := v.(int64)
if !ok {
return nil, errors.New("expected int64 for VALUE_TIME")
}
return time.UnixMilli(timestamp), nil

Copilot uses AI. Check for mistakes.
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (6)
.gitignore (1)

38-39: OK to add .history/; effectively redundant with top-level allowlist.

Given the leading "*" ignore and explicit allowlist, ".history/" and "Thumbs.db" are already ignored unless explicitly unignored elsewhere. Harmless to keep for clarity.

example_graph_test.go (5)

29-29: Prefer idiomatic Go name: ExampleFalkorDBNewTLS.

Minor style tweak to MixedCaps improves discoverability in docs.

-func ExampleFalkorDBNew_tls() {
+func ExampleFalkorDBNewTLS() {

7-7: Replace deprecated ioutil with os.ReadFile.

io/ioutil is deprecated; use os.ReadFile and drop the import.

-import (
-	"crypto/tls"
-	"crypto/x509"
-	"fmt"
-	"io/ioutil"
-	"log"
-	"os"
-	...
+import (
+	"crypto/tls"
+	"crypto/x509"
+	"fmt"
+	"log"
+	"os"
+	...
 )
@@
-	// Load CA cert
-	caCert, err := ioutil.ReadFile(tls_cacert)
+	// Load CA cert
+	caCert, err := os.ReadFile(tls_cacert)

Also applies to: 50-53


32-35: Fix typos in TLS comments.

-//     tls_cert - A a X.509 certificate to use for authenticating the  server to connected clients, masters or cluster peers. The file should be PEM formatted
-//     tls_key - A a X.509 private key to use for authenticating the  server to connected clients, masters or cluster peers. The file should be PEM formatted
-//	   tls_cacert - A PEM encoded CA's certificate file
+//     tls_cert   - An X.509 certificate to authenticate the server to connected clients, masters, or cluster peers. PEM formatted.
+//     tls_key    - An X.509 private key to authenticate the server to connected clients, masters, or cluster peers. PEM formatted.
+//     tls_cacert - A PEM-encoded CA certificate file.

38-41: Use negation instead of equality for booleans.

-	// Skip if we dont have all files to properly connect
-	if tlsready == false {
+	// Skip if we don't have all files to properly connect
+	if !tlsready {
 		return
 	}

62-69: Avoid endorsing insecure TLS by default. Gate InsecureSkipVerify behind an env flag.

Keeps the example safe-by-default while still allowing local testing.

-	// InsecureSkipVerify controls whether a client verifies the
-	// server's certificate chain and host name.
-	// If InsecureSkipVerify is true, TLS accepts any certificate
-	// presented by the server and any host name in that certificate.
-	// In this mode, TLS is susceptible to man-in-the-middle attacks.
-	// This should be used only for testing.
-	clientTLSConfig.InsecureSkipVerify = true
+	// Enable only for local testing if explicitly requested.
+	// WARNING: Susceptible to MITM; do not use in production.
+	if os.Getenv("FALKORDB_ALLOW_INSECURE") != "" {
+		clientTLSConfig.InsecureSkipVerify = true
+	}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d5d7598 and 0a000c3.

📒 Files selected for processing (2)
  • .gitignore (1 hunks)
  • example_graph_test.go (2 hunks)
🔇 Additional comments (1)
example_graph_test.go (1)

14-14: Rename to ExampleFalkorDB_SelectGraph looks good.

Example recognition by go test is preserved.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

♻️ Duplicate comments (2)
query_result.go (1)

349-361: Optional: guard type assertions to avoid panics.

Direct v.(int64) will panic on unexpected payloads. Switch to safe assertions with errors.

Example:

 case VALUE_DATETIME:
-    return time.Unix(v.(int64), 0).UTC(), nil
+    ts, ok := v.(int64)
+    if !ok { return nil, errors.New("expected int64 for VALUE_DATETIME") }
+    return time.Unix(ts, 0).UTC(), nil

Repeat for VALUE_DATE, VALUE_TIME, VALUE_DURATION.

client_test.go (1)

335-345: Harden TestGetDateTime: fix assert order and add safety checks.

Same issues as above.

 func TestGetDateTime(t *testing.T) {
   q := "RETURN localdatetime({year : 1984}) as date"
   res, err := graph.Query(q, nil, nil)
-  if err != nil {
-    t.Error(err)
-  }
-  res.Next()
-  r := res.Record()
-  dateTimeValue := r.GetByIndex(0).(time.Time)
-  assert.Equal(t, dateTimeValue.Year(), 1984, "Unexpected DateTime value")
+  if err != nil { t.Fatal(err) }
+  if res == nil { t.Fatal("Query result is nil") }
+  if !res.Next() { t.Fatal("empty result") }
+  r := res.Record()
+  val := r.GetByIndex(0)
+  dateTimeValue, ok := val.(time.Time)
+  if !ok { t.Fatalf("Expected time.Time, got %T", val) }
+  assert.Equal(t, 1984, dateTimeValue.Year(), "Unexpected DateTime value")
 }
🧹 Nitpick comments (1)
query_result.go (1)

52-56: Confirm wire protocol codes for new scalar types.

These rely on iota ordering. If server enum values differ, parsing will break. Consider pinning explicit values or add a compile-time comment with the server mapping.

Would you like a follow-up diff that assigns explicit numeric values to all VALUE_* constants to harden protocol compatibility?

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0a000c3 and 7db0a62.

📒 Files selected for processing (2)
  • client_test.go (2 hunks)
  • query_result.go (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
client_test.go (1)
record.go (1)
  • Record (3-6)
🪛 GitHub Actions: Go
client_test.go

[error] 320-320: TestGetTime failed: Not equal: expected: 10, actual: 12. Unexpected Time value. Command: go test -v ./...

🔇 Additional comments (3)
query_result.go (2)

9-9: OK to import time.

Needed for new temporal parsing.


358-361: Duration unit check.

Code assumes server returns seconds. If server ever ships millis, this will be off by 1000x. Please confirm against FalkorDB PR #1126 and add a brief comment citing the server unit.

client_test.go (1)

6-6: OK to import time.

Required for new temporal/duration tests.

Comment on lines 311 to 321
func TestGetTime(t *testing.T) {
q := "RETURN localtime({hour: 12}) AS time"
res, err := graph.Query(q, nil, nil)
if err != nil {
t.Error(err)
}
res.Next()
r := res.Record()
timeValue := r.GetByIndex(0).(time.Time)
assert.Equal(t, timeValue.Hour(), 12, "Unexpected Time value")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Harden TestGetTime: fix assert arg order and add error/empty checks.

Current failure stems from reversed assert args and potential timezone drift. After normalizing to UTC in parser, update the test for robustness.

 func TestGetTime(t *testing.T) {
   q := "RETURN localtime({hour: 12}) AS time"
   res, err := graph.Query(q, nil, nil)
-  if err != nil {
-    t.Error(err)
-  }
-  res.Next()
-  r := res.Record()
-  timeValue := r.GetByIndex(0).(time.Time)
-  assert.Equal(t, timeValue.Hour(), 12, "Unexpected Time value")
+  if err != nil { t.Fatal(err) }
+  if res == nil { t.Fatal("Query result is nil") }
+  if !res.Next() { t.Fatal("empty result") }
+  r := res.Record()
+  val := r.GetByIndex(0)
+  timeValue, ok := val.(time.Time)
+  if !ok { t.Fatalf("Expected time.Time, got %T", val) }
+  assert.Equal(t, 12, timeValue.Hour(), "Unexpected Time value")
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func TestGetTime(t *testing.T) {
q := "RETURN localtime({hour: 12}) AS time"
res, err := graph.Query(q, nil, nil)
if err != nil {
t.Error(err)
}
res.Next()
r := res.Record()
timeValue := r.GetByIndex(0).(time.Time)
assert.Equal(t, timeValue.Hour(), 12, "Unexpected Time value")
}
func TestGetTime(t *testing.T) {
q := "RETURN localtime({hour: 12}) AS time"
res, err := graph.Query(q, nil, nil)
if err != nil { t.Fatal(err) }
if res == nil { t.Fatal("Query result is nil") }
if !res.Next() { t.Fatal("empty result") }
r := res.Record()
val := r.GetByIndex(0)
timeValue, ok := val.(time.Time)
if !ok { t.Fatalf("Expected time.Time, got %T", val) }
assert.Equal(t, 12, timeValue.Hour(), "Unexpected Time value")
}
🧰 Tools
🪛 GitHub Actions: Go

[error] 320-320: TestGetTime failed: Not equal: expected: 10, actual: 12. Unexpected Time value. Command: go test -v ./...

🤖 Prompt for AI Agents
In client_test.go around lines 311 to 321, the TestGetTime has reversed assert
args and lacks checks for query errors/empty results and type assertion; update
the test to (1) fail immediately on err from graph.Query, (2) ensure res.Next()
returned true and fail the test if not, (3) retrieve the record and safely
type-assert the first field with an ok check, (4) convert the obtained time to
UTC before asserting the hour, and (5) call assert.Equal with expected value
first (12) and actual value second to fix argument order.

Comment on lines +323 to +333
func TestGetDate(t *testing.T) {
q := "RETURN date({year: 1984, month: 1, day: 1}) as date"
res, err := graph.Query(q, nil, nil)
if err != nil {
t.Error(err)
}
res.Next()
r := res.Record()
dateValue := r.GetByIndex(0).(time.Time)
assert.Equal(t, dateValue.Year(), 1984, "Unexpected Date value")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Harden TestGetDate: fix assert order and add safety checks.

Mirror the handling from TestGetTime.

 func TestGetDate(t *testing.T) {
   q := "RETURN date({year: 1984, month: 1, day: 1}) as date"
   res, err := graph.Query(q, nil, nil)
-  if err != nil {
-    t.Error(err)
-  }
-  res.Next()
-  r := res.Record()
-  dateValue := r.GetByIndex(0).(time.Time)
-  assert.Equal(t, dateValue.Year(), 1984, "Unexpected Date value")
+  if err != nil { t.Fatal(err) }
+  if res == nil { t.Fatal("Query result is nil") }
+  if !res.Next() { t.Fatal("empty result") }
+  r := res.Record()
+  val := r.GetByIndex(0)
+  dateValue, ok := val.(time.Time)
+  if !ok { t.Fatalf("Expected time.Time, got %T", val) }
+  assert.Equal(t, 1984, dateValue.Year(), "Unexpected Date value")
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func TestGetDate(t *testing.T) {
q := "RETURN date({year: 1984, month: 1, day: 1}) as date"
res, err := graph.Query(q, nil, nil)
if err != nil {
t.Error(err)
}
res.Next()
r := res.Record()
dateValue := r.GetByIndex(0).(time.Time)
assert.Equal(t, dateValue.Year(), 1984, "Unexpected Date value")
}
func TestGetDate(t *testing.T) {
q := "RETURN date({year: 1984, month: 1, day: 1}) as date"
res, err := graph.Query(q, nil, nil)
if err != nil {
t.Fatal(err)
}
if res == nil {
t.Fatal("Query result is nil")
}
if !res.Next() {
t.Fatal("empty result")
}
r := res.Record()
val := r.GetByIndex(0)
dateValue, ok := val.(time.Time)
if !ok {
t.Fatalf("Expected time.Time, got %T", val)
}
assert.Equal(t, 1984, dateValue.Year(), "Unexpected Date value")
}
🤖 Prompt for AI Agents
In client_test.go around lines 323 to 333, TestGetDate needs safety checks and
the correct assert order like TestGetTime: after Query ensure err is nil, verify
res.Next() returned true (fail the test if false), get the record and check it's
not nil, safely type-assert the value (handle non-time types), and use
assert.Equal(t, 1984, dateValue.Year(), ...) with expected value first; update
assertions and nil/type checks accordingly.

Comment on lines +347 to +358
func TestGetDuration(t *testing.T) {
q := "RETURN duration({hours: 2, minutes: 30}) AS duration"
res, err := graph.Query(q, nil, nil)
if err != nil {
t.Error(err)
}
res.Next()
r := res.Record()
durationValue := r.GetByIndex(0).(time.Duration)
expectedDuration := 2*time.Hour + 30*time.Minute
assert.Equal(t, durationValue, expectedDuration, "Unexpected Duration value")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Harden TestGetDuration: add error/empty checks and type assertion guard.

Also fix assert arg order for clarity.

 func TestGetDuration(t *testing.T) {
   q := "RETURN duration({hours: 2, minutes: 30}) AS duration"
   res, err := graph.Query(q, nil, nil)
-  if err != nil {
-    t.Error(err)
-  }
-  res.Next()
-  r := res.Record()
-  durationValue := r.GetByIndex(0).(time.Duration)
-  expectedDuration := 2*time.Hour + 30*time.Minute
-  assert.Equal(t, durationValue, expectedDuration, "Unexpected Duration value")
+  if err != nil { t.Fatal(err) }
+  if res == nil { t.Fatal("Query result is nil") }
+  if !res.Next() { t.Fatal("empty result") }
+  r := res.Record()
+  val := r.GetByIndex(0)
+  durationValue, ok := val.(time.Duration)
+  if !ok { t.Fatalf("Expected time.Duration, got %T", val) }
+  expectedDuration := 2*time.Hour + 30*time.Minute
+  assert.Equal(t, expectedDuration, durationValue, "Unexpected Duration value")
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func TestGetDuration(t *testing.T) {
q := "RETURN duration({hours: 2, minutes: 30}) AS duration"
res, err := graph.Query(q, nil, nil)
if err != nil {
t.Error(err)
}
res.Next()
r := res.Record()
durationValue := r.GetByIndex(0).(time.Duration)
expectedDuration := 2*time.Hour + 30*time.Minute
assert.Equal(t, durationValue, expectedDuration, "Unexpected Duration value")
}
func TestGetDuration(t *testing.T) {
q := "RETURN duration({hours: 2, minutes: 30}) AS duration"
res, err := graph.Query(q, nil, nil)
if err != nil {
t.Fatal(err)
}
if res == nil {
t.Fatal("Query result is nil")
}
if !res.Next() {
t.Fatal("empty result")
}
r := res.Record()
val := r.GetByIndex(0)
durationValue, ok := val.(time.Duration)
if !ok {
t.Fatalf("Expected time.Duration, got %T", val)
}
expectedDuration := 2*time.Hour + 30*time.Minute
assert.Equal(t, expectedDuration, durationValue, "Unexpected Duration value")
}
🤖 Prompt for AI Agents
In client_test.go around lines 347 to 358, the test assumes query succeeds, that
res has a record, and that the value type-asserts to time.Duration, and also
uses assert.Equal with args reversed; update the test to fail fast on query
error, check res.Next() result and t.Fatal/t.Fatalf if no record, retrieve the
value safely using a type assertion that checks the boolean ok and fails the
test if it's not a time.Duration, and call assert.Equal with expected value as
the first argument and actual value second for clearer failure messages.

Comment on lines +349 to +357
case VALUE_DATETIME:
return time.Unix(v.(int64), 0), nil

case VALUE_DATE:
return time.Unix(v.(int64), 0), nil

case VALUE_TIME:
return time.UnixMilli(v.(int64)), nil

Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix timezone drift: normalize temporal values to UTC.

Tests show hour mismatch for localtime; time.Unix/UnixMilli returns a Time in Local zone. Normalize to UTC to keep deterministic values across environments.

Apply:

 case VALUE_DATETIME:
-    return time.Unix(v.(int64), 0), nil
+    return time.Unix(v.(int64), 0).UTC(), nil

 case VALUE_DATE:
-    return time.Unix(v.(int64), 0), nil
+    return time.Unix(v.(int64), 0).UTC(), nil

 case VALUE_TIME:
-    return time.UnixMilli(v.(int64)), nil
+    return time.UnixMilli(v.(int64)).UTC(), nil
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
case VALUE_DATETIME:
return time.Unix(v.(int64), 0), nil
case VALUE_DATE:
return time.Unix(v.(int64), 0), nil
case VALUE_TIME:
return time.UnixMilli(v.(int64)), nil
case VALUE_DATETIME:
return time.Unix(v.(int64), 0).UTC(), nil
case VALUE_DATE:
return time.Unix(v.(int64), 0).UTC(), nil
case VALUE_TIME:
return time.UnixMilli(v.(int64)).UTC(), nil
🤖 Prompt for AI Agents
In query_result.go around lines 349 to 357, the temporal cases return time
values in the local zone causing timezone drift; update each return to normalize
to UTC by calling .UTC() on the constructed Time (e.g. time.Unix(v.(int64),
0).UTC(), and time.UnixMilli(v.(int64)).UTC()) so returned times are
deterministic across environments.

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.

Add support for Date time and DateTime in the go client

3 participants