Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions cpp/src/arrow/public_api_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// specific language governing permissions and limitations
// under the License.

#include <filesystem>
#include <sstream>
#include <string>

Expand Down Expand Up @@ -122,6 +123,28 @@ TEST(Misc, BuildInfo) {
ASSERT_THAT(info.full_so_version, ::testing::HasSubstr(info.so_version));
}

#ifndef _WIN32
TEST(Misc, TZDIREnvironmentVariable) {
// Find a valid zoneinfo directory
std::string tz_dir;
const char* env_tzdir = std::getenv("TZDIR");
if (env_tzdir != nullptr && std::filesystem::is_directory(env_tzdir)) {
tz_dir = env_tzdir;
} else if (std::filesystem::is_directory("/usr/share/zoneinfo")) {
tz_dir = "/usr/share/zoneinfo";
} else {
GTEST_SKIP() << "No system zoneinfo directory found";
}

// Set TZDIR and verify timezone resolution works
EnvVarGuard guard("TZDIR", tz_dir);
auto arr = ArrayFromJSON(timestamp(TimeUnit::SECOND, "UTC"), "[0]");
ASSERT_OK_AND_ASSIGN(
auto result, compute::Cast(arr, timestamp(TimeUnit::SECOND, "America/New_York")));
ASSERT_NE(result.make_array(), nullptr);
}
#endif

TEST(Misc, SetTimezoneConfig) {
#ifndef _WIN32
GTEST_SKIP() << "Can only set the Timezone database on Windows";
Expand Down
5 changes: 4 additions & 1 deletion cpp/src/arrow/vendored/datetime/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ The following changes are made:
- enclose the `date` namespace inside the `arrow_vendored` namespace
- fix 4 declarations like `CONSTCD11 date::day operator "" _d(unsigned long long d) NOEXCEPT;`
to not have offending whitespace for modern clang:
`CONSTCD11 date::day operator ""_d(unsigned long long d) NOEXCEPT;`
`CONSTCD11 date::day operator ""_d(unsigned long long d) NOEXCEPT;`
- check the TZDIR environment variable in `discover_tz_dir()` (tz.cpp) before
falling back to hardcoded paths, for compatibility with non-FHS Linux
distributions (e.g. NixOS)

## How to update

Expand Down
6 changes: 6 additions & 0 deletions cpp/src/arrow/vendored/datetime/tz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,12 @@ discover_tz_dir()
{
struct stat sb;
using namespace std;
// Check TZDIR environment variable first (POSIX standard)
const char* tz_dir_env = std::getenv("TZDIR");
if (tz_dir_env != nullptr
&& stat(tz_dir_env, &sb) == 0
&& S_ISDIR(sb.st_mode))
return tz_dir_env;
# if defined(ANDROID) || defined(__ANDROID__)
CONSTDATA auto tz_dir_default = "/apex/com.android.tzdata/etc/tz";
CONSTDATA auto tz_dir_fallback = "/system/usr/share/zoneinfo";
Expand Down
3 changes: 2 additions & 1 deletion python/pyarrow/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@
if sys.platform == "win32":
defaults['timezone_data'] = windows_has_tzdata()
elif sys.platform == "emscripten":
defaults['timezone_data'] = os.path.exists("/usr/share/zoneinfo")
tz_dir = os.environ.get("TZDIR", "/usr/share/zoneinfo")
defaults['timezone_data'] = os.path.exists(tz_dir)

try:
import cython # noqa
Expand Down