From 07c8c772e7f4c499f2606f459660dba1843ab59c Mon Sep 17 00:00:00 2001 From: Olli Draese Date: Wed, 11 Dec 2024 05:46:17 +0200 Subject: [PATCH 1/3] Fixing timezone option of formatDateTime --- src/Functions/formatDateTime.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Functions/formatDateTime.cpp b/src/Functions/formatDateTime.cpp index 56910804866..49a8b771fb7 100644 --- a/src/Functions/formatDateTime.cpp +++ b/src/Functions/formatDateTime.cpp @@ -538,6 +538,10 @@ private: *dest = '-'; offset = -offset; } + else + { + *dest = '+'; + } writeNumber2(dest + 1, offset / 3600); writeNumber2(dest + 3, offset % 3600 / 60); From ebaf3ccdccd14e0dcc21085cf16c741d1e072b51 Mon Sep 17 00:00:00 2001 From: Olli Draese Date: Wed, 11 Dec 2024 16:35:02 -0800 Subject: [PATCH 2/3] Adding a test for formatDateTime w/ timezone --- src/Functions/formatDateTime.cpp | 2 +- tests/queries/0_stateless/00718_format_datetime_1.reference | 1 + tests/queries/0_stateless/00718_format_datetime_1.sql | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Functions/formatDateTime.cpp b/src/Functions/formatDateTime.cpp index 49a8b771fb7..602c99ee369 100644 --- a/src/Functions/formatDateTime.cpp +++ b/src/Functions/formatDateTime.cpp @@ -538,7 +538,7 @@ private: *dest = '-'; offset = -offset; } - else + else { *dest = '+'; } diff --git a/tests/queries/0_stateless/00718_format_datetime_1.reference b/tests/queries/0_stateless/00718_format_datetime_1.reference index e495b69ddfc..3c2ac5eb5e0 100644 --- a/tests/queries/0_stateless/00718_format_datetime_1.reference +++ b/tests/queries/0_stateless/00718_format_datetime_1.reference @@ -3,3 +3,4 @@ 1969-12-31 23:59:59.999 1970-01-01 00:00:00.000 1970-01-01 00:00:00.001 +Wednesday+0000 diff --git a/tests/queries/0_stateless/00718_format_datetime_1.sql b/tests/queries/0_stateless/00718_format_datetime_1.sql index 855b0506f44..a48024ed994 100644 --- a/tests/queries/0_stateless/00718_format_datetime_1.sql +++ b/tests/queries/0_stateless/00718_format_datetime_1.sql @@ -3,3 +3,4 @@ select formatDateTime(toDateTime64('1962-12-08 18:11:29.123', 3, 'UTC'), '%F %T. select formatDateTime(toDateTime64('1969-12-31 23:59:59.999', 3, 'UTC'), '%F %T.%f'); select formatDateTime(toDateTime64('1970-01-01 00:00:00.000', 3, 'UTC'), '%F %T.%f'); select formatDateTime(toDateTime64('1970-01-01 00:00:00.001', 3, 'UTC'), '%F %T.%f'); +select formatDateTime(toDateTime64('2024-12-11 12:34:56.000', 3, 'UTC'), '%W%z'); From e935b2ef5439be2ce037e8a54ae5fdfd9c568dab Mon Sep 17 00:00:00 2001 From: Olli Draese Date: Fri, 13 Dec 2024 13:55:15 -0800 Subject: [PATCH 3/3] Using multiple timezones in test for format string --- tests/queries/0_stateless/00718_format_datetime_1.reference | 1 - tests/queries/0_stateless/00718_format_datetime_1.sql | 1 - .../0_stateless/03286_format_datetime_timezones.reference | 5 +++++ .../queries/0_stateless/03286_format_datetime_timezones.sql | 5 +++++ 4 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 tests/queries/0_stateless/03286_format_datetime_timezones.reference create mode 100644 tests/queries/0_stateless/03286_format_datetime_timezones.sql diff --git a/tests/queries/0_stateless/00718_format_datetime_1.reference b/tests/queries/0_stateless/00718_format_datetime_1.reference index 3c2ac5eb5e0..e495b69ddfc 100644 --- a/tests/queries/0_stateless/00718_format_datetime_1.reference +++ b/tests/queries/0_stateless/00718_format_datetime_1.reference @@ -3,4 +3,3 @@ 1969-12-31 23:59:59.999 1970-01-01 00:00:00.000 1970-01-01 00:00:00.001 -Wednesday+0000 diff --git a/tests/queries/0_stateless/00718_format_datetime_1.sql b/tests/queries/0_stateless/00718_format_datetime_1.sql index a48024ed994..855b0506f44 100644 --- a/tests/queries/0_stateless/00718_format_datetime_1.sql +++ b/tests/queries/0_stateless/00718_format_datetime_1.sql @@ -3,4 +3,3 @@ select formatDateTime(toDateTime64('1962-12-08 18:11:29.123', 3, 'UTC'), '%F %T. select formatDateTime(toDateTime64('1969-12-31 23:59:59.999', 3, 'UTC'), '%F %T.%f'); select formatDateTime(toDateTime64('1970-01-01 00:00:00.000', 3, 'UTC'), '%F %T.%f'); select formatDateTime(toDateTime64('1970-01-01 00:00:00.001', 3, 'UTC'), '%F %T.%f'); -select formatDateTime(toDateTime64('2024-12-11 12:34:56.000', 3, 'UTC'), '%W%z'); diff --git a/tests/queries/0_stateless/03286_format_datetime_timezones.reference b/tests/queries/0_stateless/03286_format_datetime_timezones.reference new file mode 100644 index 00000000000..8392f0a8335 --- /dev/null +++ b/tests/queries/0_stateless/03286_format_datetime_timezones.reference @@ -0,0 +1,5 @@ +Wednesday-0800 +Wednesday-0500 +Wednesday+0000 +Wednesday+0100 +Wednesday+0200 diff --git a/tests/queries/0_stateless/03286_format_datetime_timezones.sql b/tests/queries/0_stateless/03286_format_datetime_timezones.sql new file mode 100644 index 00000000000..66bb8ab5076 --- /dev/null +++ b/tests/queries/0_stateless/03286_format_datetime_timezones.sql @@ -0,0 +1,5 @@ +select formatDateTime(toDateTime64('2024-12-11 12:34:56.000', 3, 'US/Pacific'), '%W%z'); +select formatDateTime(toDateTime64('2024-12-11 12:34:56.000', 3, 'US/Eastern'), '%W%z'); +select formatDateTime(toDateTime64('2024-12-11 12:34:56.000', 3, 'UTC'), '%W%z'); +select formatDateTime(toDateTime64('2024-12-11 12:34:56.000', 3, 'Europe/Berlin'), '%W%z'); +select formatDateTime(toDateTime64('2024-12-11 12:34:56.000', 3, 'Europe/Athens'), '%W%z');