Skip to content

Commit

Permalink
fix str_to_date func compatible issues 9773 (#9819) (#9964)
Browse files Browse the repository at this point in the history
  • Loading branch information
b41sh authored and zz-jason committed Apr 1, 2019
1 parent 6f82fd7 commit 92096dd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
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

0 comments on commit 92096dd

Please sign in to comment.