@@ -14,6 +14,7 @@ import (
1414 "database/sql/driver"
1515 "encoding/binary"
1616 "testing"
17+ "time"
1718)
1819
1920func TestLengthEncodedInteger (t * testing.T ) {
@@ -291,3 +292,45 @@ func TestIsolationLevelMapping(t *testing.T) {
291292 t .Fatalf ("Expected error to be %q, got %q" , expectedErr , err )
292293 }
293294}
295+
296+ func TestParseDateTime (t * testing.T ) {
297+ // UTC loc
298+ {
299+ str := "2020-05-13 21:30:45"
300+ t1 , err := parseDateTime (str , time .UTC )
301+ if err != nil {
302+ t .Error (err )
303+ return
304+ }
305+ t2 := time .Date (2020 , 5 , 13 ,
306+ 21 , 30 , 45 , 0 , time .UTC )
307+ if ! t1 .Equal (t2 ) {
308+ t .Errorf ("want equal, have: %v, want: %v" , t1 , t2 )
309+ return
310+ }
311+ }
312+ // non-UTC loc
313+ {
314+ str := "2020-05-13 21:30:45"
315+ loc := time .FixedZone ("test" , 8 * 60 * 60 )
316+ t1 , err := parseDateTime (str , loc )
317+ if err != nil {
318+ t .Error (err )
319+ return
320+ }
321+ t2 := time .Date (2020 , 5 , 13 ,
322+ 21 , 30 , 45 , 0 , loc )
323+ if ! t1 .Equal (t2 ) {
324+ t .Errorf ("want equal, have: %v, want: %v" , t1 , t2 )
325+ return
326+ }
327+ }
328+ }
329+
330+ func BenchmarkParseDateTime (b * testing.B ) {
331+ str := "2020-05-13 21:30:45"
332+ loc := time .FixedZone ("test" , 8 * 60 * 60 )
333+ for i := 0 ; i < b .N ; i ++ {
334+ _ , _ = parseDateTime (str , loc )
335+ }
336+ }
0 commit comments