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

types: fix time_format is not compatible with MySQL. #9841

Merged
merged 3 commits into from
Mar 25, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1515,6 +1515,12 @@ func (s *testIntegrationSuite) TestTimeBuiltin(c *C) {
result.Check(testkit.Rows("<nil>"))
result = tk.MustQuery("SELECT TIME_FORMAT(123, '%H:%i:%s %p');")
result.Check(testkit.Rows("00:01:23 AM"))
result = tk.MustQuery("SELECT TIME_FORMAT('24:00:00', '%r');")
result.Check(testkit.Rows("12:00:00 AM"))
result = tk.MustQuery("SELECT TIME_FORMAT('25:00:00', '%r');")
result.Check(testkit.Rows("01:00:00 AM"))
result = tk.MustQuery("SELECT TIME_FORMAT('24:00:00', '%l %p');")
result.Check(testkit.Rows("12 AM"))

// for date_format
result = tk.MustQuery(`SELECT DATE_FORMAT('2017-06-15', '%W %M %e %Y %r %y');`)
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ github.com/blacktear23/go-proxyprotocol v0.0.0-20180807104634-af7a81e8dd0d h1:rQ
github.com/blacktear23/go-proxyprotocol v0.0.0-20180807104634-af7a81e8dd0d/go.mod h1:VKt7CNAQxpFpSDz3sXyj9hY/GbVsQCr0sB3w59nE7lU=
github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4=
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
github.com/client9/misspell v0.3.4 h1:ta993UF76GwbvJcIo3Y68y/M3WxlpEHPWIGDkJYwzJI=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd h1:qMd81Ts1T2OTKmB4acZcyKaMtRnY5Y44NuXGX2GFJ1w=
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
Expand Down
5 changes: 3 additions & 2 deletions types/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -1920,14 +1920,14 @@ func (t Time) convertDateFormat(b rune, buf *bytes.Buffer) error {
fmt.Fprintf(buf, "%d", t.Time.Hour())
case 'h', 'I':
t := t.Time.Hour()
if t == 0 || t == 12 {
if t%12 == 0 {
fmt.Fprintf(buf, "%02d", 12)
} else {
fmt.Fprintf(buf, "%02d", t%12)
}
case 'l':
t := t.Time.Hour()
if t == 0 || t == 12 {
if t%12 == 0 {
fmt.Fprintf(buf, "%d", 12)
} else {
fmt.Fprintf(buf, "%d", t%12)
Expand All @@ -1943,6 +1943,7 @@ func (t Time) convertDateFormat(b rune, buf *bytes.Buffer) error {
}
case 'r':
h := t.Time.Hour()
h %= 24
switch {
case h == 0:
fmt.Fprintf(buf, "%02d:%02d:%02d AM", 12, t.Time.Minute(), t.Time.Second())
Expand Down