Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ORC-1684: [C++] Find tzdb without TZDIR when in conda-environments #1882

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
15 changes: 12 additions & 3 deletions c++/src/Timezone.cc
Original file line number Diff line number Diff line change
Expand Up @@ -656,12 +656,21 @@ namespace orc {
epoch_ = utcEpoch - getVariant(utcEpoch).gmtOffset;
}

const char* getTimezoneDirectory() {
std::string getTimezoneDirectory() {
const char* dir = getenv("TZDIR");
if (!dir) {
dir = DEFAULT_TZDIR;
// this is present if we're in an activated conda environment
const char* condaPrefix = getenv("CONDA_PREFIX");
if (condaPrefix) {
std::string condaDir(condaPrefix);
condaDir += "/share/zoneinfo";
return condaDir;
} else {
dir = DEFAULT_TZDIR;
}
}
return dir;
std::string tzDir(dir);
return tzDir;
h-vetinari marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down
25 changes: 25 additions & 0 deletions c++/test/TestTimezone.cc
Original file line number Diff line number Diff line change
Expand Up @@ -437,4 +437,29 @@ namespace orc {
}
}

TEST(TestTimezone, testTzdbFromCondaEnv) {
const char* tzDirBackup = std::getenv("TZDIR");
// test only makes sense if TZDIR exists
if (tzDirBackup != nullptr) {
ASSERT_TRUE(delEnv("TZDIR"));

// remove "/share/zoneinfo" from TZDIR to get (equivalent of) CONDA_PREFIX
std::string condaPrefix(tzDirBackup);
condaPrefix += "/../..";
ASSERT_TRUE(setEnv("CONDA_PREFIX", condaPrefix.c_str()));
h-vetinari marked this conversation as resolved.
Show resolved Hide resolved

// small sample to ensure tzbd loads correctly with CONDA_PREFIX, even without TZDIR
const Timezone* la1 = &getTimezoneByName("America/Los_Angeles");
const Timezone* la2 = &getTimezoneByName("America/Los_Angeles");
EXPECT_EQ(la1, la2);
EXPECT_EQ("PST", getVariantFromZone(*la1, "1974-01-06 09:59:59"));
EXPECT_EQ("PDT", getVariantFromZone(*la1, "1974-01-06 10:00:00"));
EXPECT_EQ("PDT", getVariantFromZone(*la1, "1974-10-27 08:59:59"));
EXPECT_EQ("PST", getVariantFromZone(*la1, "1974-10-27 09:00:00"));

ASSERT_TRUE(delEnv("CONDA_PREFIX"));
ASSERT_TRUE(setEnv("TZDIR", tzDirBackup));
}
}

} // namespace orc
Loading