Skip to content

Commit b14393e

Browse files
author
James Cor
committed
fix case insensitivity for str to date
1 parent 67aa2a4 commit b14393e

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

enginetest/queries/queries.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10520,10 +10520,18 @@ var DateParseQueries = []QueryTest{
1052010520
Query: "SELECT STR_TO_DATE('a09:30:17','a%h:%i:%s')",
1052110521
Expected: []sql.Row{{"09:30:17"}},
1052210522
},
10523+
{
10524+
Query: "SELECT STR_TO_DATE('A09:30:17','A%h:%i:%s')",
10525+
Expected: []sql.Row{{"09:30:17"}},
10526+
},
1052310527
{
1052410528
Query: "SELECT STR_TO_DATE('a09:30:17','%h:%i:%s')",
1052510529
Expected: []sql.Row{{nil}},
1052610530
},
10531+
{
10532+
Query: "SELECT STR_TO_DATE('A09:30:17','a%h:%i:%s')",
10533+
Expected: []sql.Row{{nil}},
10534+
},
1052710535
{
1052810536
Query: "SELECT STR_TO_DATE('09:30:17a','%h:%i:%s')",
1052910537
Expected: []sql.Row{{"09:30:17"}},

sql/planbuilder/dateparse/date.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func ParseDateWithFormat(date, format string) (interface{}, error) {
5151
date = strings.TrimSpace(date)
5252

5353
// convert to all lowercase
54-
date = strings.ToLower(date)
54+
//date = strings.ToLower(date)
5555

5656
var dt datetime
5757
target := date
@@ -272,7 +272,7 @@ func boolPtr(a bool) *bool { return &a }
272272

273273
// Convert a week abbreviation to a defined weekday.
274274
func weekdayAbbrev(abbrev string) (time.Weekday, bool) {
275-
switch abbrev {
275+
switch strings.ToLower(abbrev) {
276276
case "sun":
277277
return time.Sunday, true
278278
case "mon":
@@ -293,7 +293,7 @@ func weekdayAbbrev(abbrev string) (time.Weekday, bool) {
293293

294294
// Convert a month abbreviation to a defined month.
295295
func monthAbbrev(abbrev string) (time.Month, bool) {
296-
switch abbrev {
296+
switch strings.ToLower(abbrev) {
297297
case "jan":
298298
return time.January, true
299299
case "feb":
@@ -327,7 +327,7 @@ func monthAbbrev(abbrev string) (time.Month, bool) {
327327
func monthName(name string) (month time.Month, charCount int, ok bool) {
328328
for i := 1; i < 13; i++ {
329329
m := time.Month(i)
330-
if strings.HasPrefix(name, strings.ToLower(m.String())) {
330+
if strings.HasPrefix(strings.ToLower(name), strings.ToLower(m.String())) {
331331
return m, len(m.String()), true
332332
}
333333
}

sql/planbuilder/dateparse/parsers.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ package dateparse
22

33
import (
44
"fmt"
5-
"time"
5+
"strings"
6+
"time"
67
)
78

89
// parser defines a function that processes a string and returns the
@@ -39,7 +40,7 @@ func parseAmPm(result *datetime, chars string) (rest string, _ error) {
3940
if len(chars) < 2 {
4041
return "", fmt.Errorf("expected > 2 chars, found %d", len(chars))
4142
}
42-
switch chars[:2] {
43+
switch strings.ToLower(chars[:2]) {
4344
case "am":
4445
result.am = boolPtr(true)
4546
case "pm":

0 commit comments

Comments
 (0)