From 5015cb13859dd4554318bec2eaadadd98cdc0df9 Mon Sep 17 00:00:00 2001 From: Qiaolin Yu <90088090+Qiaolin-Yu@users.noreply.github.com> Date: Tue, 20 Sep 2022 16:48:08 +0800 Subject: [PATCH] cherry pick #37820 to release-5.1 Signed-off-by: ti-srebot --- types/time.go | 10 +++++++++- types/time_test.go | 3 +++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/types/time.go b/types/time.go index 7dbafacad131f..c57b645ec99fe 100644 --- a/types/time.go +++ b/types/time.go @@ -558,9 +558,17 @@ func GetFsp(s string) int8 { // GetFracIndex finds the last '.' for get fracStr, index = -1 means fracStr not found. // but for format like '2019.01.01 00:00:00', the index should be -1. +// It will not be affected by the time zone suffix. For format like '2020-01-01 12:00:00.123456+05:00', the index should be 19. func GetFracIndex(s string) (index int) { + tzIndex, _, _, _, _ := GetTimezone(s) + var end int + if tzIndex != -1 { + end = tzIndex - 1 + } else { + end = len(s) - 1 + } index = -1 - for i := len(s) - 1; i >= 0; i-- { + for i := end; i >= 0; i-- { if unicode.IsPunct(rune(s[i])) { if s[i] == '.' { index = i diff --git a/types/time_test.go b/types/time_test.go index 79bc957dad8a0..b98663c3c3bf9 100644 --- a/types/time_test.go +++ b/types/time_test.go @@ -115,6 +115,9 @@ func (s *testTimeSuite) TestDateTime(c *C) { {"2020-05-28 23:59:59T T00:00:00", "2020-05-28 23:59:59"}, {"2020-10-22 10:31-10:12", "2020-10-22 10:31:10"}, {"2018.01.01 01:00:00", "2018-01-01 01:00:00"}, + + // For issue 35291 + {"2020-01-01 12:00:00.123456+05:00", "2020-01-01 07:00:00.123456"}, } for _, test := range table {