@@ -13,7 +13,6 @@ import (
13
13
"database/sql"
14
14
"database/sql/driver"
15
15
"encoding/binary"
16
- "fmt"
17
16
"testing"
18
17
"time"
19
18
)
@@ -294,23 +293,6 @@ func TestIsolationLevelMapping(t *testing.T) {
294
293
}
295
294
}
296
295
297
- func deprecatedParseDateTime (str string , loc * time.Location ) (t time.Time , err error ) {
298
- const base = "0000-00-00 00:00:00.000000"
299
- switch len (str ) {
300
- case 10 , 19 , 21 , 22 , 23 , 24 , 25 , 26 : // up to "YYYY-MM-DD HH:MM:SS.MMMMMM"
301
- if str == base [:len (str )] {
302
- return
303
- }
304
- if loc == time .UTC {
305
- return time .Parse (timeFormat [:len (str )], str )
306
- }
307
- return time .ParseInLocation (timeFormat [:len (str )], str , loc )
308
- default :
309
- err = fmt .Errorf ("invalid time string: %s" , str )
310
- return
311
- }
312
- }
313
-
314
296
func TestParseDateTime (t * testing.T ) {
315
297
cases := []struct {
316
298
name string
@@ -364,9 +346,13 @@ func TestParseDateTime(t *testing.T) {
364
346
} {
365
347
for _ , cc := range cases {
366
348
t .Run (cc .name + "-" + loc .String (), func (t * testing.T ) {
367
- want , err := deprecatedParseDateTime (cc .str , loc )
368
- if err != nil {
369
- t .Fatal (err )
349
+ var want time.Time
350
+ if cc .str != sDate0 && cc .str != sDateTime0 {
351
+ var err error
352
+ want , err = time .ParseInLocation (timeFormat [:len (cc .str )], cc .str , loc )
353
+ if err != nil {
354
+ t .Fatal (err )
355
+ }
370
356
}
371
357
got , err := parseDateTime ([]byte (cc .str ), loc )
372
358
if err != nil {
@@ -449,29 +435,3 @@ func TestParseDateTimeFail(t *testing.T) {
449
435
})
450
436
}
451
437
}
452
-
453
- func BenchmarkParseDateTime (b * testing.B ) {
454
- str := "2020-05-13 21:30:45"
455
- loc := time .FixedZone ("test" , 8 * 60 * 60 )
456
- for i := 0 ; i < b .N ; i ++ {
457
- _ , _ = deprecatedParseDateTime (str , loc )
458
- }
459
- }
460
-
461
- func BenchmarkParseByteDateTime (b * testing.B ) {
462
- bStr := []byte ("2020-05-25 23:22:01.159491" )
463
- loc := time .FixedZone ("test" , 8 * 60 * 60 )
464
- b .ResetTimer ()
465
- for i := 0 ; i < b .N ; i ++ {
466
- _ , _ = parseDateTime (bStr , loc )
467
- }
468
- }
469
-
470
- func BenchmarkParseByteDateTimeStringCast (b * testing.B ) {
471
- bStr := []byte ("2020-05-25 23:22:01.159491" )
472
- loc := time .FixedZone ("test" , 8 * 60 * 60 )
473
- b .ResetTimer ()
474
- for i := 0 ; i < b .N ; i ++ {
475
- _ , _ = deprecatedParseDateTime (string (bStr ), loc )
476
- }
477
- }
0 commit comments