Skip to content

Commit

Permalink
types: fix wrong str_to_date() microseconds with leading zeros are no…
Browse files Browse the repository at this point in the history
…t converted correctly (#30122) (#30222)

close #30078
  • Loading branch information
ti-srebot authored Apr 15, 2022
1 parent 081e449 commit 939fe72
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
1 change: 1 addition & 0 deletions expression/builtin_time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1413,6 +1413,7 @@ func (s *testEvaluatorSuite) TestStrToDate(c *C) {
{"15-01-2001 1:59:58.", "%d-%m-%Y %H:%i:%s.%f", true, types.KindMysqlTime, time.Date(2001, 1, 15, 1, 59, 58, 000000000, time.Local)},
{"15-01-2001 1:9:8.999", "%d-%m-%Y %H:%i:%s.%f", true, types.KindMysqlTime, time.Date(2001, 1, 15, 1, 9, 8, 999000000, time.Local)},
{"15-01-2001 1:9:8.999", "%d-%m-%Y %H:%i:%S.%f", true, types.KindMysqlTime, time.Date(2001, 1, 15, 1, 9, 8, 999000000, time.Local)},
{"2003-01-02 10:11:12.0012", "%Y-%m-%d %H:%i:%S.%f", true, types.KindMysqlTime, time.Date(2003, 1, 2, 10, 11, 12, 1200000, time.Local)},
{"2003-01-02 10:11:12 PM", "%Y-%m-%d %H:%i:%S %p", false, types.KindMysqlTime, time.Time{}},
{"10:20:10AM", "%H:%i:%S%p", false, types.KindMysqlTime, time.Time{}},
// test %@(skip alpha), %#(skip number), %.(skip punct)
Expand Down
3 changes: 1 addition & 2 deletions types/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -3226,11 +3226,10 @@ func microSeconds(t *CoreTime, input string, ctx map[string]int) (string, bool)
}

v, ok := parseDigits(input, length)

if !ok {
return input, false
}
for v > 0 && v*10 < 1000000 {
for i := length; i < 6; i++ {
v *= 10
}
t.setMicrosecond(uint32(v))
Expand Down

0 comments on commit 939fe72

Please sign in to comment.