From 9ba64750a3bcb46e19ead3bdf2689b762d5a3233 Mon Sep 17 00:00:00 2001 From: lzmhhh123 Date: Thu, 21 Mar 2019 14:35:03 +0800 Subject: [PATCH 1/2] fix --- types/time.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/types/time.go b/types/time.go index 87b51266094e2..81ab97f76d6f9 100644 --- a/types/time.go +++ b/types/time.go @@ -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) @@ -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()) From 77559c1b8b870c1649948507673102694d81a9f5 Mon Sep 17 00:00:00 2001 From: lzmhhh123 Date: Thu, 21 Mar 2019 14:41:20 +0800 Subject: [PATCH 2/2] add tests --- expression/integration_test.go | 6 ++++++ go.sum | 1 + 2 files changed, 7 insertions(+) diff --git a/expression/integration_test.go b/expression/integration_test.go index 5896eea147ff6..4b70b4792ee9f 100644 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -1515,6 +1515,12 @@ func (s *testIntegrationSuite) TestTimeBuiltin(c *C) { result.Check(testkit.Rows("")) 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');`) diff --git a/go.sum b/go.sum index f77fa64d84138..ec75a6d624e5c 100644 --- a/go.sum +++ b/go.sum @@ -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=