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: fix str_to_date func compatible (#9819) #9964

Merged
merged 1 commit into from
Apr 1, 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
2 changes: 2 additions & 0 deletions expression/builtin_time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1256,6 +1256,8 @@ func (s *testEvaluatorSuite) TestStrToDate(c *C) {
{"15-01-2001 1:59:58.", "%d-%m-%Y %H:%i:%s.%f", true, time.Date(2001, 1, 15, 1, 59, 58, 000000000, time.Local)},
{"15-01-2001 1:9:8.999", "%d-%m-%Y %H:%i:%s.%f", true, time.Date(2001, 1, 15, 1, 9, 8, 999000000, time.Local)},
{"15-01-2001 1:9:8.999", "%d-%m-%Y %H:%i:%S.%f", true, time.Date(2001, 1, 15, 1, 9, 8, 999000000, time.Local)},
{"2003-01-02 10:11:12 PM", "%Y-%m-%d %H:%i:%S %p", false, time.Time{}},
{"10:20:10AM", "%H:%i:%S%p", false, time.Time{}},
}

fc := funcs[ast.StrToDate]
Expand Down
4 changes: 4 additions & 0 deletions types/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -1920,6 +1920,9 @@ func mysqlTimeFix(t *MysqlTime, ctx map[string]int) error {
_ = yearOfDay
}
if valueAMorPm, ok := ctx["%p"]; ok {
if _, ok := ctx["%H"]; ok {
return ErrInvalidTimeFormat.GenWithStackByArgs(t)
}
if t.hour == 0 {
return ErrInvalidTimeFormat.GenWithStackByArgs(t)
}
Expand Down Expand Up @@ -2300,6 +2303,7 @@ func hour24Numeric(t *MysqlTime, input string, ctx map[string]int) (string, bool
return input, false
}
t.hour = v
ctx["%H"] = v
return input[length:], true
}

Expand Down