More compliant with glibc

This commit is contained in:
cangyin 2024-08-30 23:48:37 +08:00
parent 44dcee5b11
commit 60790d6c92
3 changed files with 19 additions and 3 deletions

View File

@ -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

View File

@ -0,0 +1,4 @@
UTC
Asia/Shanghai
Asia/Shanghai
Europe/Amsterdam

View 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()";