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
10 changes: 0 additions & 10 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,6 @@ func parseDateTime(b []byte, loc *time.Location) (time.Time, error) {
if err != nil {
return time.Time{}, err
}
if year <= 0 {
year = 1
}

if b[4] != '-' {
return time.Time{}, fmt.Errorf("bad value for field: `%c`", b[4])
}
Expand All @@ -130,9 +126,6 @@ func parseDateTime(b []byte, loc *time.Location) (time.Time, error) {
if err != nil {
return time.Time{}, err
}
if m <= 0 {
m = 1
}
month := time.Month(m)

if b[7] != '-' {
Expand All @@ -143,9 +136,6 @@ func parseDateTime(b []byte, loc *time.Location) (time.Time, error) {
if err != nil {
return time.Time{}, err
}
if day <= 0 {
day = 1
}
if len(b) == 10 {
return time.Date(year, month, day, 0, 0, 0, 0, loc), nil
}
Expand Down
27 changes: 27 additions & 0 deletions utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,33 @@ func TestParseDateTime(t *testing.T) {
}
}

func TestInvalidDateTime(t *testing.T) {
cases := []struct {
name string
str string
want time.Time
}{
{
name: "parse datetime without day",
str: "0000-00-00 21:30:45",
want: time.Date(0, 0, 0, 21, 30, 45, 0, time.UTC),
},
}

for _, cc := range cases {
t.Run(cc.name, func(t *testing.T) {
got, err := parseDateTime([]byte(cc.str), time.UTC)
if err != nil {
t.Fatal(err)
}

if !cc.want.Equal(got) {
t.Fatalf("want: %v, but got %v", cc.want, got)
}
})
}
}

func TestParseDateTimeFail(t *testing.T) {
cases := []struct {
name string
Expand Down