Skip to content

fix a bug that values of time(1),time(3),time(5) will generate 00:00:00 #529

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

Merged
merged 2 commits into from
Jun 22, 2021
Merged
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
18 changes: 10 additions & 8 deletions replication/row_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -1410,11 +1410,10 @@ func decodeTime2(data []byte, dec uint16) (string, int, error) {
intPart := int64(0)
frac := int64(0)
switch dec {
case 1:
case 2:
case 1, 2:
intPart = int64(BFixedLengthInt(data[0:3])) - TIMEF_INT_OFS
frac = int64(data[3])
if intPart < 0 && frac > 0 {
if intPart < 0 && frac != 0 {
/*
Negative values are stored with reverse fractional part order,
for binary sort compatibility.
Expand All @@ -1436,11 +1435,10 @@ func decodeTime2(data []byte, dec uint16) (string, int, error) {
frac -= 0x100 /* -(0x100 - frac) */
}
tmp = intPart<<24 + frac*10000
case 3:
case 4:
case 3, 4:
intPart = int64(BFixedLengthInt(data[0:3])) - TIMEF_INT_OFS
frac = int64(binary.BigEndian.Uint16(data[3:5]))
if intPart < 0 && frac > 0 {
if intPart < 0 && frac != 0 {
/*
Fix reverse fractional part order: "0x10000 - frac".
See comments for FSP=1 and FSP=2 above.
Expand All @@ -1450,9 +1448,9 @@ func decodeTime2(data []byte, dec uint16) (string, int, error) {
}
tmp = intPart<<24 + frac*100

case 5:
case 6:
case 5, 6:
tmp = int64(BFixedLengthInt(data[0:6])) - TIMEF_OFS
return timeFormat(tmp, n)
default:
intPart = int64(BFixedLengthInt(data[0:3])) - TIMEF_INT_OFS
tmp = intPart << 24
Expand All @@ -1462,6 +1460,10 @@ func decodeTime2(data []byte, dec uint16) (string, int, error) {
return "00:00:00", n, nil
}

return timeFormat(tmp, n)
}

func timeFormat(tmp int64, n int) (string, int, error) {
hms := int64(0)
sign := ""
if tmp < 0 {
Expand Down