Skip to content

Commit

Permalink
Merge pull request #6 from lexaficus/master
Browse files Browse the repository at this point in the history
Added Time type to unmarshal
  • Loading branch information
m1nor authored Oct 7, 2016
2 parents 2982363 + ad82408 commit 9aff1a0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"reflect"
"strconv"
"strings"
"time"
)

func unescape(s string) string {
Expand Down Expand Up @@ -50,6 +51,8 @@ func unmarshal(value interface{}, data string) (err error) {
*v = m.(float64)
case *string:
*v = unescape(data)
case *time.Time:
*v, err = time.ParseInLocation("2006-01-02 15:04:05", data, time.UTC)
case *[]int:
if !isArray(data) {
//noinspection GoPlaceholderCount
Expand Down
9 changes: 7 additions & 2 deletions marshal_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package clickhouse

import (
"testing"

"github.com/stretchr/testify/assert"
"testing"
"time"
)

func BenchmarkMarshalString(b *testing.B) {
Expand All @@ -21,6 +21,7 @@ func TestUnmarshal(t *testing.T) {
valInt32 int32
valInt64 int64
valString string
valTime time.Time
valUnsupported testing.T
valFloat32 float32
valFloat64 float64
Expand Down Expand Up @@ -57,6 +58,10 @@ func TestUnmarshal(t *testing.T) {
assert.Equal(t, "String1'", valString)
assert.NoError(t, err)

err = unmarshal(&valTime, "2016-10-07 19:21:17")
assert.Equal(t, time.Date(2016, 10, 7, 19, 21, 17, 0, time.UTC), valTime)
assert.NoError(t, err)

err = unmarshal(&valUnsupported, "10")
assert.Error(t, err)

Expand Down

0 comments on commit 9aff1a0

Please sign in to comment.