Skip to content
Merged
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
7 changes: 6 additions & 1 deletion driver/kafka/kafka2.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,12 @@ func DateTimeValue(dateTime string, loc *time.Location) int64 {
if err != nil {
return 0
}
return tm2.UnixMilli()
timeSlice := strings.Split(tm2.Format("15:04:05.000"), ".")
if len(timeSlice) != 2 {
return 0
}
ms, err := strconv.ParseInt(timeSlice[1], 10, 64)
return tm2.Unix()*1000 + ms
}
func DateValue(date string) int64 {
tm2, err := time.Parse(LAYOUT, date+" 00:00:00")
Expand Down
30 changes: 0 additions & 30 deletions driver/kafka/kafka2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package kafka
import (
"encoding/base64"
"testing"
"time"
)

func TestDecimalValueFromStringMysql(t *testing.T) {
Expand All @@ -21,32 +20,3 @@ func TestTimeValue(t *testing.T) {
test("01:02:03", 1, 2, 3, 0, false)
test("-800:02:03.100000", 800, 2, 3, 100000, true)
}

func TestDateTimeValue(t *testing.T) {
tests := []struct {
dateTime string
want int64
}{
{
dateTime: "9999-12-31 23:59:59",
want: 253402300799000,
},
{
dateTime: "1900-03-02 04:06:09",
want: -2203790031000,
},
{
dateTime: "5900-03-02 04:06:09",
want: 124024017969000,
},
}

for _, tt := range tests {
t.Run(tt.dateTime, func(t *testing.T) {
realDateTime := DateTimeValue(tt.dateTime, time.Local)
if realDateTime != tt.want {
t.Errorf("parse dateTime = %v, want %v", realDateTime, tt.want)
}
})
}
}