Skip to content

Commit

Permalink
evalengine: Fix week overflow (#14859)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbussink authored Dec 26, 2023
1 parent 2176095 commit 04028a9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions go/mysql/datetime/datetime.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,12 +315,16 @@ func (d Date) Week(mode int) int {
year, week := d.SundayWeek()
if year < d.Year() {
return 0
} else if year > d.Year() {
return 53
}
return week
case 1:
year, week := d.ISOWeek()
if year < d.Year() {
return 0
} else if year > d.Year() {
return 53
}
return week
case 2:
Expand All @@ -333,12 +337,16 @@ func (d Date) Week(mode int) int {
year, week := d.Sunday4DayWeek()
if year < d.Year() {
return 0
} else if year > d.Year() {
return 53
}
return week
case 5:
year, week := d.MondayWeek()
if year < d.Year() {
return 0
} else if year > d.Year() {
return 53
}
return week
case 6:
Expand Down
16 changes: 16 additions & 0 deletions go/vt/vtgate/evalengine/compiler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,22 @@ func TestCompilerSingle(t *testing.T) {
expression: `DAYOFMONTH(0)`,
result: `INT64(0)`,
},
{
expression: `week('2023-12-31', 4)`,
result: `INT64(53)`,
},
{
expression: `week('2023-12-31', 2)`,
result: `INT64(53)`,
},
{
expression: `week('2024-12-31', 1)`,
result: `INT64(53)`,
},
{
expression: `week('2024-12-31', 5)`,
result: `INT64(53)`,
},
}

tz, _ := time.LoadLocation("Europe/Madrid")
Expand Down

0 comments on commit 04028a9

Please sign in to comment.