File tree Expand file tree Collapse file tree 2 files changed +17
-8
lines changed Expand file tree Collapse file tree 2 files changed +17
-8
lines changed Original file line number Diff line number Diff line change @@ -2,22 +2,27 @@ package ftime
22
33import (
44 "database/sql/driver"
5+ "errors"
56)
67
78// Scan 实现sql的反序列化
8- func (t Time ) Scan (value interface {}) {
9- switch UsedFormatType {
10- case TIMESTAMP :
11- value = t .timestamp ()
12- case TEXT :
13- value = t .formatText ()
9+ func (t * Time ) Scan (value interface {}) error {
10+ if t == nil {
11+ return nil
12+ }
13+
14+ switch v := value .(type ) {
15+ case int64 :
16+ return t .parseTSInt64 (v )
17+ case string :
18+ return t .parseTS (v )
1419 default :
15- value = t . timestamp ( )
20+ return errors . New ( "unsupport type" )
1621 }
1722}
1823
1924// Value 实现sql的序列化
20- func (t * Time ) Value () (driver.Value , error ) {
25+ func (t Time ) Value () (driver.Value , error ) {
2126 switch UsedFormatType {
2227 case TIMESTAMP :
2328 return t .timestamp (), nil
Original file line number Diff line number Diff line change @@ -100,6 +100,10 @@ func (t Time) formatText() []byte {
100100func (t Time ) timestamp () int64 {
101101 var ts int64
102102
103+ if t .T ().IsZero () {
104+ return 0
105+ }
106+
103107 switch UsedTimestampLength {
104108 case Length10 :
105109 ts = time .Time (t ).Unix ()
You can’t perform that action at this time.
0 commit comments