Skip to content

Commit 2c6aa27

Browse files
committed
removed deprecatedParseDateTime from test
1 parent 32ad982 commit 2c6aa27

File tree

1 file changed

+7
-47
lines changed

1 file changed

+7
-47
lines changed

utils_test.go

+7-47
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"database/sql"
1414
"database/sql/driver"
1515
"encoding/binary"
16-
"fmt"
1716
"testing"
1817
"time"
1918
)
@@ -294,23 +293,6 @@ func TestIsolationLevelMapping(t *testing.T) {
294293
}
295294
}
296295

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-
314296
func TestParseDateTime(t *testing.T) {
315297
cases := []struct {
316298
name string
@@ -364,9 +346,13 @@ func TestParseDateTime(t *testing.T) {
364346
} {
365347
for _, cc := range cases {
366348
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+
}
370356
}
371357
got, err := parseDateTime([]byte(cc.str), loc)
372358
if err != nil {
@@ -449,29 +435,3 @@ func TestParseDateTimeFail(t *testing.T) {
449435
})
450436
}
451437
}
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

Comments
 (0)