From 1610bcca89171edbda45d43feeb73b33d63ce011 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Fri, 12 Apr 2019 02:21:37 +0300 Subject: [PATCH] Fixed wrong toISOWeek result for 1970 year --- .../00935_to_iso_week_first_year.reference | 15 +++++++++++++++ .../0_stateless/00935_to_iso_week_first_year.sql | 1 + libs/libcommon/include/common/DateLUTImpl.h | 2 +- 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 dbms/tests/queries/0_stateless/00935_to_iso_week_first_year.reference create mode 100644 dbms/tests/queries/0_stateless/00935_to_iso_week_first_year.sql diff --git a/dbms/tests/queries/0_stateless/00935_to_iso_week_first_year.reference b/dbms/tests/queries/0_stateless/00935_to_iso_week_first_year.reference new file mode 100644 index 00000000000..9e498be5588 --- /dev/null +++ b/dbms/tests/queries/0_stateless/00935_to_iso_week_first_year.reference @@ -0,0 +1,15 @@ +0000-00-00 1 1970 +1970-01-02 1 1970 +1970-01-03 1 1970 +1970-01-04 1 1970 +1970-01-05 2 1970 +1970-01-06 2 1970 +1970-01-07 2 1970 +1970-01-08 2 1970 +1970-01-09 2 1970 +1970-01-10 2 1970 +1970-01-11 2 1970 +1970-01-12 3 1970 +1970-01-13 3 1970 +1970-01-14 3 1970 +1970-01-15 3 1970 diff --git a/dbms/tests/queries/0_stateless/00935_to_iso_week_first_year.sql b/dbms/tests/queries/0_stateless/00935_to_iso_week_first_year.sql new file mode 100644 index 00000000000..1691606a676 --- /dev/null +++ b/dbms/tests/queries/0_stateless/00935_to_iso_week_first_year.sql @@ -0,0 +1 @@ +SELECT toDate('1970-01-01') + number AS d, toISOWeek(d), toISOYear(d) FROM numbers(15); \ No newline at end of file diff --git a/libs/libcommon/include/common/DateLUTImpl.h b/libs/libcommon/include/common/DateLUTImpl.h index 0a713207f60..28d536fc93d 100644 --- a/libs/libcommon/include/common/DateLUTImpl.h +++ b/libs/libcommon/include/common/DateLUTImpl.h @@ -371,7 +371,7 @@ public: /// The week number 1 is the first week in year that contains 4 or more days (that's more than half). inline unsigned toISOWeek(DayNum d) const { - return 1 + (toFirstDayNumOfWeek(d) - toFirstDayNumOfISOYear(d)) / 7; + return 1 + DayNum(toFirstDayNumOfWeek(d) - toFirstDayNumOfISOYear(d)) / 7; } inline unsigned toISOWeek(time_t t) const