Skip to content

Commit

Permalink
types: fix incorrect weekday for ALLOW_INVALID_DATES mode (#10864) (
Browse files Browse the repository at this point in the history
  • Loading branch information
sre-bot authored Apr 8, 2020
1 parent 9c61329 commit 6cd41a4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion types/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion types/mytime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
16 changes: 16 additions & 0 deletions types/mytime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 6cd41a4

Please sign in to comment.