Skip to content

Commit

Permalink
util/convert: convert year handle case mysql.Time
Browse files Browse the repository at this point in the history
  • Loading branch information
coocood committed Sep 6, 2015
1 parent 0054f81 commit 97ea35c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions util/types/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ func Convert(val interface{}, target *FieldType) (v interface{}, err error) { //
switch x := val.(type) {
case string:
intVal, err = StrToInt(x)
case mysql.Time:
return int16(x.Year()), nil
default:
intVal, err = ToInt64(x)
}
Expand Down
4 changes: 4 additions & 0 deletions util/types/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ func (s *testTypeConvertSuite) TestConvertType(c *C) {
c.Assert(v, Equals, int16(2015))
v, err = Convert(1800, ft)
c.Assert(err, NotNil)
dt, err := mysql.ParseDate("2015-11-11")
c.Assert(err, IsNil)
v, err = Convert(dt, ft)
c.Assert(v, Equals, int16(2015))
}

func testToInt64(c *C, val interface{}, expect int64) {
Expand Down

0 comments on commit 97ea35c

Please sign in to comment.