From 60790d6c9299a25189bf5df77bb798e326b65d6b Mon Sep 17 00:00:00 2001 From: cangyin Date: Fri, 30 Aug 2024 23:48:37 +0800 Subject: [PATCH] More compliant with glibc --- src/Common/DateLUT.cpp | 8 +++++--- tests/queries/0_stateless/03206_timezone_env.reference | 4 ++++ tests/queries/0_stateless/03206_timezone_env.sh | 10 ++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 tests/queries/0_stateless/03206_timezone_env.reference create mode 100644 tests/queries/0_stateless/03206_timezone_env.sh diff --git a/src/Common/DateLUT.cpp b/src/Common/DateLUT.cpp index 55648bc587a..a0d0b95a381 100644 --- a/src/Common/DateLUT.cpp +++ b/src/Common/DateLUT.cpp @@ -46,12 +46,14 @@ std::string determineDefaultTimeZone() /// may give wrong timezone names - store the name as it is, if possible. std::string tz_name; - if (!tz_env_var.empty()) + if (tz_env_var) { error_prefix = std::string("Could not determine time zone from TZ variable value: '") + tz_env_var + "': "; if (*tz_env_var == ':') ++tz_env_var; + else if (*tz_env_var == '\0') + tz_env_var = "UTC"; tz_file_path = tz_env_var; tz_name = tz_env_var; @@ -68,7 +70,7 @@ std::string determineDefaultTimeZone() /// Read symlink but not transitive. /// Example: /// /etc/localtime -> /usr/share/zoneinfo//UTC - /// /usr/share/zoneinfo//UTC -> UCT + /// /usr/share/zoneinfo//UTC -> UTC /// But the preferred time zone name is pointed by the first link (UTC), and the second link is just an internal detail. if (FS::isSymlink(tz_file_path)) { @@ -89,7 +91,7 @@ std::string determineDefaultTimeZone() fs::path relative_path = tz_file_path.lexically_relative(tz_database_path); if (!relative_path.empty() && *relative_path.begin() != ".." && *relative_path.begin() != ".") - return tz_name.empty() ? relative_path.string() : tz_name; + return relative_path.string(); } /// Try the same with full symlinks resolution diff --git a/tests/queries/0_stateless/03206_timezone_env.reference b/tests/queries/0_stateless/03206_timezone_env.reference new file mode 100644 index 00000000000..8508f8a7772 --- /dev/null +++ b/tests/queries/0_stateless/03206_timezone_env.reference @@ -0,0 +1,4 @@ +UTC +Asia/Shanghai +Asia/Shanghai +Europe/Amsterdam diff --git a/tests/queries/0_stateless/03206_timezone_env.sh b/tests/queries/0_stateless/03206_timezone_env.sh new file mode 100644 index 00000000000..d1cc4bf0e35 --- /dev/null +++ b/tests/queries/0_stateless/03206_timezone_env.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +# shellcheck source=../shell_config.sh +. "$CUR_DIR"/../shell_config.sh + +TZ='' ${CLICKHOUSE_LOCAL} --query "SELECT timezone()"; +TZ='Asia/Shanghai' ${CLICKHOUSE_LOCAL} --query "SELECT timezone()"; +TZ=':Asia/Shanghai' ${CLICKHOUSE_LOCAL} --query "SELECT timezone()"; +TZ=':/usr/share/zoneinfo/Europe/Amsterdam' ${CLICKHOUSE_LOCAL} --query "SELECT timezone()";