diff --git a/src/Common/DateLUT.cpp b/src/Common/DateLUT.cpp index f9bbe2fbf40..fd966d30273 100644 --- a/src/Common/DateLUT.cpp +++ b/src/Common/DateLUT.cpp @@ -52,6 +52,8 @@ std::string determineDefaultTimeZone() if (*tz_env_var == ':') ++tz_env_var; + else if (*tz_env_var == '\0') + return "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..d3c2aef4b52 --- /dev/null +++ b/tests/queries/0_stateless/03206_timezone_env.reference @@ -0,0 +1,5 @@ +UTC +Asia/Shanghai +Asia/Shanghai +Europe/Amsterdam +Poland diff --git a/tests/queries/0_stateless/03206_timezone_env.sh b/tests/queries/0_stateless/03206_timezone_env.sh new file mode 100755 index 00000000000..a769e703113 --- /dev/null +++ b/tests/queries/0_stateless/03206_timezone_env.sh @@ -0,0 +1,11 @@ +#!/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()"; +TZ='Poland' ${CLICKHOUSE_LOCAL} --query "SELECT timezone()";