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: partial fix #4340, support date time format when parse duration #4380

Merged
merged 4 commits into from Aug 30, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions expression/integration_test.go
Expand Up @@ -1183,6 +1183,18 @@ func (s *testIntegrationSuite) TestTimeBuiltin(c *C) {
result = tk.MustQuery(`SELECT hour("12:13:14.123456"), hour("12:13:14.000010"), hour("272:59:55"), hour(020005), hour(null), hour("27aaaa2:59:55");`)
result.Check(testkit.Rows("12 12 272 2 <nil> <nil>"))

// for hour, issue #4340
result = tk.MustQuery(`SELECT HOUR(20171222020005);`)
result.Check(testkit.Rows("2"))
result = tk.MustQuery(`SELECT HOUR(20171222020005.1);`)
result.Check(testkit.Rows("2"))
result = tk.MustQuery(`SELECT HOUR(20171222020005.1e0);`)
result.Check(testkit.Rows("2"))
result = tk.MustQuery(`SELECT HOUR("20171222020005");`)
result.Check(testkit.Rows("2"))
result = tk.MustQuery(`SELECT HOUR("20171222020005.1");`)
result.Check(testkit.Rows("2"))

// for minute
result = tk.MustQuery(`SELECT minute("12:13:14.123456"), minute("12:13:14.000010"), minute("272:59:55"), minute(null), minute("27aaaa2:59:55");`)
result.Check(testkit.Rows("13 13 59 <nil> <nil>"))
Expand Down
2 changes: 1 addition & 1 deletion util/types/convert.go
Expand Up @@ -181,7 +181,7 @@ func StrToDuration(sc *variable.StatementContext, str string, fsp int) (t Time,
}
// Timestamp format is 'YYYYMMDDHHMMSS' or 'YYMMDDHHMMSS', which length is 12.
// See #3923, it explains what we do here.
if len(str) >= 12 {
if length >= 12 {
t, err = StrToDateTime(str, fsp)
if err == nil {
return t, nil
Expand Down
6 changes: 3 additions & 3 deletions util/types/time.go
Expand Up @@ -951,9 +951,9 @@ func ParseDuration(str string, fsp int) (Duration, error) {
_, err = fmt.Sscanf(str, "%1d", &second)
} else {
// Maybe only contains date.
_, err = ParseDate(str)
if err == nil {
return ZeroDuration, nil
t, err1 := ParseDatetime(str)
if err1 == nil {
return t.ConvertToDuration()
}
return ZeroDuration, errors.Trace(ErrInvalidTimeFormat)
}
Expand Down