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) (#30223)

close #30078
  • Loading branch information
ti-srebot authored Jun 16, 2022
1 parent da3bcc6 commit eda0ae5
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions expression/builtin_time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1451,6 +1451,7 @@ func TestStrToDate(t *testing.T) {
{"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
2 changes: 1 addition & 1 deletion types/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -3193,7 +3193,7 @@ func microSeconds(t *CoreTime, input string, ctx map[string]int) (string, bool)
t.setMicrosecond(0)
return input, true
}
for v > 0 && v*10 < 1000000 {
for i := step; i < 6; i++ {
v *= 10
}
t.setMicrosecond(uint32(v))
Expand Down

0 comments on commit eda0ae5

Please sign in to comment.