Skip to content

Commit

Permalink
fix(proto): fix DateTime overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
ernado committed Jul 7, 2022
1 parent d5f2158 commit a81a32e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion proto/datetime.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package proto
import "time"

// DateTime represents DateTime type.
type DateTime int32
type DateTime uint32

// ToDateTime converts time.Time to DateTime.
func ToDateTime(t time.Time) DateTime {
Expand Down
16 changes: 16 additions & 0 deletions query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,22 @@ func requireEqual[T any](t *testing.T, a, b proto.ColumnOf[T]) {
}
}

func TestDateTimeOverflow(t *testing.T) {
t.Parallel()
ctx := context.Background()
conn := Conn(t)
var data proto.ColDateTime
query := Query{
Body: "SELECT toDateTime('2061-02-01 00:00:00') as v",
Result: proto.Results{
{Name: "v", Data: &data},
},
}
require.NoError(t, conn.Do(ctx, query))
require.Equal(t, 1, data.Rows())
require.Equal(t, "2061-02-01 00:00:00", data.Row(0).Format("2006-01-02 15:04:05"))
}

func TestClient_Query(t *testing.T) {
ctx := context.Background()
t.Parallel()
Expand Down

0 comments on commit a81a32e

Please sign in to comment.