Skip to content
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

types: fix incorrect weekday for ALLOW_INVALID_DATES mode #10864

Merged
merged 10 commits into from
Jul 12, 2019
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
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()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return t1.Weekday()
t1, _ := t.GoTime(gotime.Local)
return t1.Weekday()

I think this is better.

Copy link
Member Author

@b41sh b41sh Jul 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can't ignore err check

}
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)
}
}