diff --git a/server/util.go b/server/util.go index c80289c1b741e..5314e24684c04 100644 --- a/server/util.go +++ b/server/util.go @@ -43,7 +43,6 @@ import ( "strconv" "time" - "github.com/pingcap/errors" "github.com/pingcap/parser/mysql" "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/types" @@ -201,16 +200,7 @@ func dumpBinaryTime(dur time.Duration) (data []byte) { return } -func dumpBinaryDateTime(data []byte, t types.Time, loc *time.Location) ([]byte, error) { - if t.Type == mysql.TypeTimestamp && loc != nil { - // TODO: Consider time_zone variable. - t1, err := t.Time.GoTime(time.Local) - if err != nil { - return nil, errors.Errorf("FATAL: convert timestamp %v go time return error!", t.Time) - } - t.Time = types.FromGoTime(t1.In(loc)) - } - +func dumpBinaryDateTime(data []byte, t types.Time) []byte { year, mon, day := t.Time.Year(), t.Time.Month(), t.Time.Day() switch t.Type { case mysql.TypeTimestamp, mysql.TypeDatetime: @@ -223,7 +213,7 @@ func dumpBinaryDateTime(data []byte, t types.Time, loc *time.Location) ([]byte, data = dumpUint16(data, uint16(year)) //year data = append(data, byte(mon), byte(day)) } - return data, nil + return data } func dumpBinaryRow(buffer []byte, columns []*ColumnInfo, row chunk.Row) ([]byte, error) { @@ -259,11 +249,7 @@ func dumpBinaryRow(buffer []byte, columns []*ColumnInfo, row chunk.Row) ([]byte, mysql.TypeTinyBlob, mysql.TypeMediumBlob, mysql.TypeLongBlob, mysql.TypeBlob: buffer = dumpLengthEncodedString(buffer, row.GetBytes(i)) case mysql.TypeDate, mysql.TypeDatetime, mysql.TypeTimestamp: - var err error - buffer, err = dumpBinaryDateTime(buffer, row.GetTime(i), nil) - if err != nil { - return buffer, err - } + buffer = dumpBinaryDateTime(buffer, row.GetTime(i)) case mysql.TypeDuration: buffer = append(buffer, dumpBinaryTime(row.GetDuration(i, 0).Duration)...) case mysql.TypeEnum: diff --git a/server/util_test.go b/server/util_test.go index c7eba5959fbc0..4d979f09dcd38 100644 --- a/server/util_test.go +++ b/server/util_test.go @@ -61,19 +61,16 @@ func (s *testUtilSuite) TearDownSuite(c *C) { func (s *testUtilSuite) TestDumpBinaryTime(c *C) { t, err := types.ParseTimestamp(nil, "0000-00-00 00:00:00.0000000") c.Assert(err, IsNil) - d, err := dumpBinaryDateTime(nil, t, nil) - c.Assert(err, IsNil) + d := dumpBinaryDateTime(nil, t) c.Assert(d, DeepEquals, []byte{11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}) t, err = types.ParseDatetime(nil, "0000-00-00 00:00:00.0000000") c.Assert(err, IsNil) - d, err = dumpBinaryDateTime(nil, t, nil) - c.Assert(err, IsNil) + d = dumpBinaryDateTime(nil, t) c.Assert(d, DeepEquals, []byte{11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}) t, err = types.ParseDate(nil, "0000-00-00") c.Assert(err, IsNil) - d, err = dumpBinaryDateTime(nil, t, nil) - c.Assert(err, IsNil) + d = dumpBinaryDateTime(nil, t) c.Assert(d, DeepEquals, []byte{4, 0, 0, 0, 0}) myDuration, err := types.ParseDuration(nil, "0000-00-00 00:00:00.0000000", 6)