Skip to content

Commit

Permalink
[BugFix] fix incorrect result of yearweek
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitrs1983 committed Sep 16, 2024
1 parent 0df6bd2 commit 212af87
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
11 changes: 0 additions & 11 deletions be/src/exprs/time_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,17 +571,6 @@ DEFINE_BINARY_FUNCTION_WITH_IMPL(year_week_with_modeImpl, t, m) {
date_value.to_date(&year, &month, &day);
uint to_year = 0;
int week = TimeFunctions::compute_week(year, month, day, TimeFunctions::week_mode(m | 2), &to_year);

if (week == 53 && day >= 29 && !(m & 4)) {
int monday_first = m & WEEK_MONDAY_FIRST;
int daynr_of_last_day = TimeFunctions::compute_daynr(year, 12, 31);
int weekday_of_last_day = TimeFunctions::compute_weekday(daynr_of_last_day, !monday_first);

if (weekday_of_last_day - monday_first < 2) {
++to_year;
week = 1;
}
}
return to_year * 100 + week;
}
DEFINE_TIME_BINARY_FN(year_week_with_mode, TYPE_DATETIME, TYPE_INT, TYPE_INT);
Expand Down
5 changes: 5 additions & 0 deletions test/sql/test_datetime/R/test_yearweek
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- name: test_yearweek
select yearweek('2023-12-31', 2), yearweek('2024-01-01', 2);
-- result:
202353 202353
-- !result
2 changes: 2 additions & 0 deletions test/sql/test_datetime/T/test_yearweek
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- name: test_yearweek
select yearweek('2023-12-31', 2), yearweek('2024-01-01', 2);

0 comments on commit 212af87

Please sign in to comment.