From 2dd7420fc7e14f3167b81f59949d78903c83a653 Mon Sep 17 00:00:00 2001 From: Habibullah Oladepo Date: Sun, 3 Apr 2022 23:42:39 +0100 Subject: [PATCH] Add tests for toLastDayOfMonth --- .../02251_last_day_of_month.reference | 7 +++ .../0_stateless/02251_last_day_of_month.sql | 46 +++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 tests/queries/0_stateless/02251_last_day_of_month.reference create mode 100644 tests/queries/0_stateless/02251_last_day_of_month.sql diff --git a/tests/queries/0_stateless/02251_last_day_of_month.reference b/tests/queries/0_stateless/02251_last_day_of_month.reference new file mode 100644 index 00000000000..0b83aff1e42 --- /dev/null +++ b/tests/queries/0_stateless/02251_last_day_of_month.reference @@ -0,0 +1,7 @@ +2021-09-30 2021-09-30 2021-09-30 +2021-03-31 2021-03-31 2021-03-31 +2021-02-28 2021-02-28 2021-02-28 +2020-02-29 2020-02-29 2020-02-29 +2021-12-31 2021-12-31 2021-12-31 +2020-12-31 2020-12-31 2020-12-31 +2020-12-31 2020-12-31 diff --git a/tests/queries/0_stateless/02251_last_day_of_month.sql b/tests/queries/0_stateless/02251_last_day_of_month.sql new file mode 100644 index 00000000000..1261f051e17 --- /dev/null +++ b/tests/queries/0_stateless/02251_last_day_of_month.sql @@ -0,0 +1,46 @@ +-- month with 30 days +WITH + toDate('2021-09-12') AS date_value, + toDateTime('2021-09-12 11:22:33') AS date_time_value, + toDateTime64('2021-09-12 11:22:33', 3) AS date_time_64_value +SELECT toLastDayOfMonth(date_value), toLastDayOfMonth(date_time_value), toLastDayOfMonth(date_time_64_value); + +-- month with 31 days +WITH + toDate('2021-03-12') AS date_value, + toDateTime('2021-03-12 11:22:33') AS date_time_value, + toDateTime64('2021-03-12 11:22:33', 3) AS date_time_64_value +SELECT toLastDayOfMonth(date_value), toLastDayOfMonth(date_time_value), toLastDayOfMonth(date_time_64_value); + +-- non leap year February +WITH + toDate('2021-02-12') AS date_value, + toDateTime('2021-02-12 11:22:33') AS date_time_value, + toDateTime64('2021-02-12 11:22:33', 3) AS date_time_64_value +SELECT toLastDayOfMonth(date_value), toLastDayOfMonth(date_time_value), toLastDayOfMonth(date_time_64_value); + +-- leap year February +WITH + toDate('2020-02-12') AS date_value, + toDateTime('2020-02-12 11:22:33') AS date_time_value, + toDateTime64('2020-02-12 11:22:33', 3) AS date_time_64_value +SELECT toLastDayOfMonth(date_value), toLastDayOfMonth(date_time_value), toLastDayOfMonth(date_time_64_value); + +-- December 31 for non-leap year +WITH + toDate('2021-12-12') AS date_value, + toDateTime('2021-12-12 11:22:33') AS date_time_value, + toDateTime64('2021-12-12 11:22:33', 3) AS date_time_64_value +SELECT toLastDayOfMonth(date_value), toLastDayOfMonth(date_time_value), toLastDayOfMonth(date_time_64_value); + +-- December 31 for leap year +WITH + toDate('2020-12-12') AS date_value, + toDateTime('2020-12-12 11:22:33') AS date_time_value, + toDateTime64('2020-12-12 11:22:33', 3) AS date_time_64_value +SELECT toLastDayOfMonth(date_value), toLastDayOfMonth(date_time_value), toLastDayOfMonth(date_time_64_value); + +-- aliases +WITH + toDate('2020-12-12') AS date_value +SELECT last_day(date_value), LAST_DAY(date_value);