@@ -11,44 +11,6 @@ import (
1111 "github.com/siddontang/go/hack"
1212)
1313
14- func toBinaryDateTime (t time.Time ) ([]byte , error ) {
15- var buf bytes.Buffer
16-
17- if t .IsZero () {
18- return nil , nil
19- }
20-
21- year , month , day := t .Year (), t .Month (), t .Day ()
22- hour , min , sec := t .Hour (), t .Minute (), t .Second ()
23- nanosec := t .Nanosecond ()
24-
25- if nanosec > 0 {
26- buf .WriteByte (byte (11 ))
27- _ = binary .Write (& buf , binary .LittleEndian , uint16 (year ))
28- buf .WriteByte (byte (month ))
29- buf .WriteByte (byte (day ))
30- buf .WriteByte (byte (hour ))
31- buf .WriteByte (byte (min ))
32- buf .WriteByte (byte (sec ))
33- _ = binary .Write (& buf , binary .LittleEndian , uint32 (nanosec / 1000 ))
34- } else if hour > 0 || min > 0 || sec > 0 {
35- buf .WriteByte (byte (7 ))
36- _ = binary .Write (& buf , binary .LittleEndian , uint16 (year ))
37- buf .WriteByte (byte (month ))
38- buf .WriteByte (byte (day ))
39- buf .WriteByte (byte (hour ))
40- buf .WriteByte (byte (min ))
41- buf .WriteByte (byte (sec ))
42- } else {
43- buf .WriteByte (byte (4 ))
44- _ = binary .Write (& buf , binary .LittleEndian , uint16 (year ))
45- buf .WriteByte (byte (month ))
46- buf .WriteByte (byte (day ))
47- }
48-
49- return buf .Bytes (), nil
50- }
51-
5214func FormatTextValue (value interface {}) ([]byte , error ) {
5315 switch v := value .(type ) {
5416 case int8 :
@@ -88,6 +50,44 @@ func FormatTextValue(value interface{}) ([]byte, error) {
8850 }
8951}
9052
53+ func toBinaryDateTime (t time.Time ) ([]byte , error ) {
54+ var buf bytes.Buffer
55+
56+ if t .IsZero () {
57+ return nil , nil
58+ }
59+
60+ year , month , day := t .Year (), t .Month (), t .Day ()
61+ hour , min , sec := t .Hour (), t .Minute (), t .Second ()
62+ nanosec := t .Nanosecond ()
63+
64+ if nanosec > 0 {
65+ buf .WriteByte (byte (11 ))
66+ _ = binary .Write (& buf , binary .LittleEndian , uint16 (year ))
67+ buf .WriteByte (byte (month ))
68+ buf .WriteByte (byte (day ))
69+ buf .WriteByte (byte (hour ))
70+ buf .WriteByte (byte (min ))
71+ buf .WriteByte (byte (sec ))
72+ _ = binary .Write (& buf , binary .LittleEndian , uint32 (nanosec / 1000 ))
73+ } else if hour > 0 || min > 0 || sec > 0 {
74+ buf .WriteByte (byte (7 ))
75+ _ = binary .Write (& buf , binary .LittleEndian , uint16 (year ))
76+ buf .WriteByte (byte (month ))
77+ buf .WriteByte (byte (day ))
78+ buf .WriteByte (byte (hour ))
79+ buf .WriteByte (byte (min ))
80+ buf .WriteByte (byte (sec ))
81+ } else {
82+ buf .WriteByte (byte (4 ))
83+ _ = binary .Write (& buf , binary .LittleEndian , uint16 (year ))
84+ buf .WriteByte (byte (month ))
85+ buf .WriteByte (byte (day ))
86+ }
87+
88+ return buf .Bytes (), nil
89+ }
90+
9191func formatBinaryValue (value interface {}) ([]byte , error ) {
9292 switch v := value .(type ) {
9393 case int8 :
0 commit comments