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
2
2
3
3
import (
4
4
"database/sql/driver"
5
+ "errors"
5
6
)
6
7
7
8
// 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 )
14
19
default :
15
- value = t . timestamp ( )
20
+ return errors . New ( "unsupport type" )
16
21
}
17
22
}
18
23
19
24
// Value 实现sql的序列化
20
- func (t * Time ) Value () (driver.Value , error ) {
25
+ func (t Time ) Value () (driver.Value , error ) {
21
26
switch UsedFormatType {
22
27
case TIMESTAMP :
23
28
return t .timestamp (), nil
Original file line number Diff line number Diff line change @@ -100,6 +100,10 @@ func (t Time) formatText() []byte {
100
100
func (t Time ) timestamp () int64 {
101
101
var ts int64
102
102
103
+ if t .T ().IsZero () {
104
+ return 0
105
+ }
106
+
103
107
switch UsedTimestampLength {
104
108
case Length10 :
105
109
ts = time .Time (t ).Unix ()
You can’t perform that action at this time.
0 commit comments