Skip to content

Commit 2330e41

Browse files
committed
fix weekofyear
1 parent 8acd85d commit 2330e41

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

sql/expression/function/time.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,7 +1336,11 @@ func (dtf *UnaryDatetimeFunc) EvalChild(ctx *sql.Context, row sql.Row) (interfac
13361336
}
13371337

13381338
ret, _, err := types.DatetimeMaxPrecision.Convert(ctx, val)
1339-
return ret, err
1339+
if err != nil {
1340+
ctx.Warn(1292, "%s", types.ErrConvertingToTime.New(val).Error())
1341+
return nil, nil
1342+
}
1343+
return ret, nil
13401344
}
13411345

13421346
// String implements the fmt.Stringer interface.
@@ -1477,8 +1481,7 @@ func (*MonthName) CollationCoercibility(ctx *sql.Context) (collation sql.Collati
14771481
func (d *MonthName) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
14781482
val, err := d.EvalChild(ctx, row)
14791483
if err != nil {
1480-
ctx.Warn(1292, "%s", types.ErrConvertingToTime.New(val).Error())
1481-
return nil, nil
1484+
return nil, err
14821485
}
14831486

14841487
switch v := val.(type) {
@@ -1579,6 +1582,10 @@ func (m *WeekOfYear) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
15791582

15801583
switch v := val.(type) {
15811584
case time.Time:
1585+
if v.Equal(types.ZeroTime) {
1586+
ctx.Warn(1292, "%s", types.ErrConvertingToTime.New(val).Error())
1587+
return nil, nil
1588+
}
15821589
_, wk := v.ISOWeek()
15831590
return wk, nil
15841591
case nil:

0 commit comments

Comments
 (0)