Skip to content

Commit

Permalink
expression: fix ADD_DATE daylight saving time change (pingcap#20871) (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-srebot authored Nov 6, 2020
1 parent 0b0c41b commit 45571c5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
9 changes: 9 additions & 0 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6166,3 +6166,12 @@ func (s *testSuite) TestIssue20237(c *C) {
tk.MustExec(`insert into s values(-37),(105),(-22),(-56),(124),(105),(111),(-5);`)
tk.MustQuery(`select count(distinct t.a, t.b) from t join s on t.b= s.b;`).Check(testkit.Rows("4"))
}

func (s *testSuite) TestIssue19667(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("CREATE TABLE t (a DATETIME)")
tk.MustExec("INSERT INTO t VALUES('1988-04-17 01:59:59')")
tk.MustQuery(`SELECT DATE_ADD(a, INTERVAL 1 SECOND) FROM t`).Check(testkit.Rows("1988-04-17 02:00:00"))
}
2 changes: 1 addition & 1 deletion expression/builtin_time.go
Original file line number Diff line number Diff line change
Expand Up @@ -2852,7 +2852,7 @@ func (du *baseDateArithmitical) add(ctx sessionctx.Context, date types.Time, int
return types.ZeroTime, true, err
}

goTime, err := date.GoTime(time.Local)
goTime, err := date.GoTime(time.UTC)
if err := handleInvalidTimeError(ctx, err); err != nil {
return types.ZeroTime, true, err
}
Expand Down
2 changes: 1 addition & 1 deletion types/core_time.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func compareTime(a, b CoreTime) int {
// When we execute select date_add('2018-01-31',interval 1 month) in mysql we got 2018-02-28
// but in tidb we got 2018-03-03.
// Dig it and we found it's caused by golang api time.Date(year int, month Month, day, hour, min, sec, nsec int, loc *Location) Time ,
// it says October 32 converts to November 1 ,it conflits with mysql.
// it says October 32 converts to November 1 ,it conflicts with mysql.
// See https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_date-add
func AddDate(year, month, day int64, ot gotime.Time) (nt gotime.Time) {
df := getFixDays(int(year), int(month), int(day), ot)
Expand Down

0 comments on commit 45571c5

Please sign in to comment.