From a2e1ffbe3825c3c4eb9cdae2e6198c777b76d09e Mon Sep 17 00:00:00 2001 From: Manan Gupta Date: Thu, 26 Dec 2024 14:31:11 +0530 Subject: [PATCH] feat: fix the problem Signed-off-by: Manan Gupta --- go/mysql/datetime/spec.go | 5 +---- go/vt/vtgate/evalengine/compiler_test.go | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/go/mysql/datetime/spec.go b/go/mysql/datetime/spec.go index ce19126ce55..c5c45c9b74b 100644 --- a/go/mysql/datetime/spec.go +++ b/go/mysql/datetime/spec.go @@ -374,10 +374,7 @@ func (u fmtWeek0) parse(t *timeparts, bytes string) (string, bool) { type fmtWeek1 struct{} func (fmtWeek1) format(dst []byte, t DateTime, prec uint8) []byte { - year, week := t.Date.ISOWeek() - if year < t.Date.Year() { - week = 0 - } + week := t.Date.Week(1) return appendInt(dst, week, 2) } diff --git a/go/vt/vtgate/evalengine/compiler_test.go b/go/vt/vtgate/evalengine/compiler_test.go index 2680fbc47de..88c13a479ed 100644 --- a/go/vt/vtgate/evalengine/compiler_test.go +++ b/go/vt/vtgate/evalengine/compiler_test.go @@ -741,9 +741,25 @@ func TestCompilerSingle(t *testing.T) { result: `VARBINARY("\x00\x00\x00\xff")`, }, { - expression: `DATE_FORMAT(timestamp '2024-12-30 10:34:58', "%u");`, + expression: `DATE_FORMAT(timestamp '2024-12-30 10:34:58', "%u")`, result: `VARCHAR("53")`, }, + { + expression: `WEEK(timestamp '2024-12-30 10:34:58', 0)`, + result: `INT64(52)`, + }, + { + expression: `WEEK(timestamp '2024-12-30 10:34:58', 1)`, + result: `INT64(53)`, + }, + { + expression: `WEEK(timestamp '2024-01-01 10:34:58', 0)`, + result: `INT64(0)`, + }, + { + expression: `WEEK(timestamp '2024-01-01 10:34:58', 1)`, + result: `INT64(1)`, + }, } tz, _ := time.LoadLocation("Europe/Madrid")