Skip to content

Commit

Permalink
*: fix microseconds behaviour in DATE_ADD() (#11280) (#11288)
Browse files Browse the repository at this point in the history
  • Loading branch information
sre-bot authored and zz-jason committed Jul 18, 2019
1 parent 6baed7d commit b9b6c97
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
12 changes: 12 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4391,3 +4391,15 @@ func (s *testIntegrationSuite) TestIssue10675(c *C) {
testkit.Rows("1"))
tk.MustQuery(`select * from t where a > 184467440737095516167.1;`).Check(testkit.Rows())
}

func (s *testIntegrationSuite) TestIssue11257(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustQuery(`select DATE_ADD('2007-03-28 22:08:28',INTERVAL -2 SECOND_MICROSECOND);`).Check(
testkit.Rows("2007-03-28 22:08:27.800000"))
tk.MustQuery(`select DATE_ADD('2007-03-28 22:08:28',INTERVAL -2 MINUTE_MICROSECOND);`).Check(
testkit.Rows("2007-03-28 22:08:27.800000"))
tk.MustQuery(`select DATE_ADD('2007-03-28 22:08:28',INTERVAL -2 HOUR_MICROSECOND);`).Check(
testkit.Rows("2007-03-28 22:08:27.800000"))
tk.MustQuery(`select DATE_ADD('2007-03-28 22:08:28',INTERVAL -2 DAY_MICROSECOND);`).Check(
testkit.Rows("2007-03-28 22:08:27.800000"))
}
5 changes: 4 additions & 1 deletion types/fsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,12 @@ func ParseFrac(s string, fsp int) (v int, overflow bool, err error) {
return
}

// alignFrac is used to generate alignment frac, like `100` -> `100000`
// alignFrac is used to generate alignment frac, like `100` -> `100000` ,`-100` -> `-100000`
func alignFrac(s string, fsp int) string {
sl := len(s)
if sl > 0 && s[0] == '-' {
sl = sl - 1
}
if sl < fsp {
return s + strings.Repeat("0", fsp-sl)
}
Expand Down
4 changes: 4 additions & 0 deletions types/fsp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,8 @@ func (s *FspTest) TestAlignFrac(c *C) {
c.Assert(obtained, Equals, "100000")
obtained = alignFrac("10000000000", 6)
c.Assert(obtained, Equals, "10000000000")
obtained = alignFrac("-100", 6)
c.Assert(obtained, Equals, "-100000")
obtained = alignFrac("-10000000000", 6)
c.Assert(obtained, Equals, "-10000000000")
}

0 comments on commit b9b6c97

Please sign in to comment.