Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expression,types: improve str_to_date builtin function compatibility (9617) #9817

Merged
merged 2 commits into from
Mar 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions expression/builtin_time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,9 @@ func (s *testEvaluatorSuite) TestStrToDate(c *C) {
Success bool
Expect time.Time
}{
{"10/28/2011 9:46:29 pm", "%m/%d/%Y %l:%i:%s %p", true, time.Date(2011, 10, 28, 21, 46, 29, 0, time.Local)},
{"10/28/2011 9:46:29 Pm", "%m/%d/%Y %l:%i:%s %p", true, time.Date(2011, 10, 28, 21, 46, 29, 0, time.Local)},
{"2011/10/28 9:46:29 am", "%Y/%m/%d %l:%i:%s %p", true, time.Date(2011, 10, 28, 9, 46, 29, 0, time.Local)},
{"20161122165022", `%Y%m%d%H%i%s`, true, time.Date(2016, 11, 22, 16, 50, 22, 0, time.Local)},
{"2016 11 22 16 50 22", `%Y%m%d%H%i%s`, true, time.Date(2016, 11, 22, 16, 50, 22, 0, time.Local)},
{"16-50-22 2016 11 22", `%H-%i-%s%Y%m%d`, true, time.Date(2016, 11, 22, 16, 50, 22, 0, time.Local)},
Expand Down
12 changes: 9 additions & 3 deletions types/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -2346,11 +2346,17 @@ const (
)

func isAMOrPM(t *MysqlTime, input string, ctx map[string]int) (string, bool) {
if strings.HasPrefix(input, "AM") {
if len(input) < 2 {
return input, false
}

s := strings.ToLower(input[:2])
switch s {
case "am":
ctx["%p"] = constForAM
} else if strings.HasPrefix(input, "PM") {
case "pm":
ctx["%p"] = constForPM
} else {
default:
return input, false
}
return input[2:], true
Expand Down