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

time: fix the fraction loss when encountering time string with timezone suffix (#37820) #38010

Closed
Closed
Show file tree
Hide file tree
Changes from all 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
10 changes: 9 additions & 1 deletion types/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,9 +575,17 @@ func GetFsp(s string) int {

// 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
Expand Down
3 changes: 3 additions & 0 deletions types/time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ func TestDateTime(t *testing.T) {
{"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 {
Expand Down