Skip to content

Commit

Permalink
apply unit:day special logic on unit:hour for INTERVAL segment (#8146)
Browse files Browse the repository at this point in the history
  • Loading branch information
imiskolee authored and ngaut committed Nov 2, 2018
1 parent 8ed4330 commit 31f5abd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions expression/builtin_time.go
Expand Up @@ -2577,8 +2577,8 @@ func (du *baseDateArithmitical) getIntervalFromString(ctx sessionctx.Context, ar
if isNull || err != nil {
return "", true, errors.Trace(err)
}
// unit "DAY" has to be specially handled.
if strings.ToLower(unit) == "day" {
// unit "DAY" and "HOUR" has to be specially handled.
if toLower := strings.ToLower(unit); toLower == "day" || toLower == "hour" {
if strings.ToLower(interval) == "true" {
interval = "1"
} else if strings.ToLower(interval) == "false" {
Expand Down
5 changes: 5 additions & 0 deletions expression/integration_test.go
Expand Up @@ -1807,6 +1807,11 @@ func (s *testIntegrationSuite) TestTimeBuiltin(c *C) {
{"\"2009-01-01\"", "6/4", "HOUR_MINUTE", "2009-01-04 12:20:00", "2008-12-28 11:40:00"},
{"\"2009-01-01\"", "6/0", "HOUR_MINUTE", "<nil>", "<nil>"},
{"\"1970-01-01 12:00:00\"", "CAST(6/4 AS DECIMAL(3,1))", "HOUR_MINUTE", "1970-01-01 13:05:00", "1970-01-01 10:55:00"},
//for issue #8077
{"\"2012-01-02\"", "\"prefix8\"", "HOUR", "2012-01-02 08:00:00", "2012-01-01 16:00:00"},
{"\"2012-01-02\"", "\"prefix8prefix\"", "HOUR", "2012-01-02 08:00:00", "2012-01-01 16:00:00"},
{"\"2012-01-02\"", "\"8:00\"", "HOUR", "2012-01-02 08:00:00", "2012-01-01 16:00:00"},
{"\"2012-01-02\"", "\"8:00:00\"", "HOUR", "2012-01-02 08:00:00", "2012-01-01 16:00:00"},
}
for _, tc := range dateArithmeticalTests {
addDate := fmt.Sprintf("select adddate(%s, interval %s %s);", tc.Date, tc.Interval, tc.Unit)
Expand Down

0 comments on commit 31f5abd

Please sign in to comment.