mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-19 16:20:50 +00:00
More compliant with glibc
This commit is contained in:
parent
44dcee5b11
commit
60790d6c92
@ -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
|
||||
|
4
tests/queries/0_stateless/03206_timezone_env.reference
Normal file
4
tests/queries/0_stateless/03206_timezone_env.reference
Normal file
@ -0,0 +1,4 @@
|
||||
UTC
|
||||
Asia/Shanghai
|
||||
Asia/Shanghai
|
||||
Europe/Amsterdam
|
10
tests/queries/0_stateless/03206_timezone_env.sh
Normal file
10
tests/queries/0_stateless/03206_timezone_env.sh
Normal file
@ -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()";
|
Loading…
Reference in New Issue
Block a user