Skip to content

Commit ae3a154

Browse files
committed
fix yearweek, update test case for quarter
1 parent 2330e41 commit ae3a154

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

enginetest/queries/function_queries.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2093,10 +2093,9 @@ var FunctionQueryTests = []QueryTest{
20932093
ExpectedWarningsCount: 1,
20942094
},
20952095
{
2096-
Query: "select quarter('0000-00-00')",
2097-
Expected: []sql.Row{{nil}},
2098-
ExpectedWarning: mysql.ERTruncatedWrongValue,
2099-
ExpectedWarningsCount: 1,
2096+
// This is not a valid time string in MySQL, but we allow it
2097+
Query: "select quarter('0000-00-00')",
2098+
Expected: []sql.Row{{nil}},
21002099
},
21012100
{
21022101
Query: "select quarter('0000-01-01')",

sql/expression/function/time.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,13 @@ func (d *YearWeek) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
616616
if date == nil {
617617
return nil, nil
618618
}
619+
620+
dateTime, ok := date.(time.Time)
621+
if !ok || dateTime.Equal(types.ZeroTime) {
622+
ctx.Warn(1292, "%s", types.ErrConvertingToTime.New(dateVal).Error())
623+
return nil, nil
624+
}
625+
619626
yyyy, ok := year(date).(int)
620627
if !ok {
621628
return nil, sql.ErrInvalidArgumentDetails.New("YEARWEEK", "invalid year")

0 commit comments

Comments
 (0)