diff --git a/types/format_test.go b/types/format_test.go index 493ac31e75..d4434dc301 100644 --- a/types/format_test.go +++ b/types/format_test.go @@ -62,7 +62,7 @@ func (s *testTimeSuite) TestTimeFormatMethod(c *C) { // %W %w %a is not compatible in this case because Week() use GoTime() currently. "0000-01-00 00:00:00.123456", `%b %M %m %c %D %d %e %j %k %h %i %p %r %T %s %f %U %u %V %v %a %W %w %X %x %Y %y %%`, - `Jan January 01 1 0th 00 0 000 0 12 00 AM 12:00:00 AM 00:00:00 00 123456 00 00 00 52 Sun Sunday 0 4294967295 4294967295 0000 00 %`, + `Jan January 01 1 0th 00 0 000 0 12 00 AM 12:00:00 AM 00:00:00 00 123456 00 00 00 52 Fri Friday 5 4294967295 4294967295 0000 00 %`, }, } for i, t := range tblDate { diff --git a/types/mytime.go b/types/mytime.go index 5ee12ec20a..733571f023 100644 --- a/types/mytime.go +++ b/types/mytime.go @@ -70,8 +70,9 @@ func (t MysqlTime) Microsecond() int { func (t MysqlTime) Weekday() gotime.Weekday { // TODO: Consider time_zone variable. t1, err := t.GoTime(gotime.Local) + // allow invalid dates if err != nil { - return 0 + return t1.Weekday() } return t1.Weekday() } diff --git a/types/mytime_test.go b/types/mytime_test.go index f2897c8789..76a32f4b40 100644 --- a/types/mytime_test.go +++ b/types/mytime_test.go @@ -271,3 +271,19 @@ func (s *testMyTimeSuite) TestAddDate(c *C) { c.Assert(res.Year(), Equals, t.year+t.ot.Year()) } } + +func (s *testMyTimeSuite) TestWeekday(c *C) { + tests := []struct { + Input MysqlTime + Expect string + }{ + {MysqlTime{2019, 01, 01, 0, 0, 0, 0}, "Tuesday"}, + {MysqlTime{2019, 02, 31, 0, 0, 0, 0}, "Sunday"}, + {MysqlTime{2019, 04, 31, 0, 0, 0, 0}, "Wednesday"}, + } + + for _, tt := range tests { + weekday := tt.Input.Weekday() + c.Check(weekday.String(), Equals, tt.Expect) + } +}