diff --git a/types/ftime/sql.go b/types/ftime/sql.go index 37cfa41..e3889bd 100644 --- a/types/ftime/sql.go +++ b/types/ftime/sql.go @@ -2,22 +2,27 @@ package ftime import ( "database/sql/driver" + "errors" ) // Scan 实现sql的反序列化 -func (t Time) Scan(value interface{}) { - switch UsedFormatType { - case TIMESTAMP: - value = t.timestamp() - case TEXT: - value = t.formatText() +func (t *Time) Scan(value interface{}) error { + if t == nil { + return nil + } + + switch v := value.(type) { + case int64: + return t.parseTSInt64(v) + case string: + return t.parseTS(v) default: - value = t.timestamp() + return errors.New("unsupport type") } } // Value 实现sql的序列化 -func (t *Time) Value() (driver.Value, error) { +func (t Time) Value() (driver.Value, error) { switch UsedFormatType { case TIMESTAMP: return t.timestamp(), nil diff --git a/types/ftime/time.go b/types/ftime/time.go index a9c7eb6..cf07497 100644 --- a/types/ftime/time.go +++ b/types/ftime/time.go @@ -100,6 +100,10 @@ func (t Time) formatText() []byte { func (t Time) timestamp() int64 { var ts int64 + if t.T().IsZero() { + return 0 + } + switch UsedTimestampLength { case Length10: ts = time.Time(t).Unix()