types: fix incorrect weekday for ALLOW_INVALID_DATES mode (#10864)
This commit is contained in:
@ -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 {
|
||||
|
||||
@ -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()
|
||||
}
|
||||
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user