h-vetinari commented on code in PR #1882:
URL: https://github.com/apache/orc/pull/1882#discussion_r1560459812
##########
c++/test/TestTimezone.cc:
##########
@@ -421,20 +422,61 @@ namespace orc {
}
TEST(TestTimezone, testMissingTZDB) {
- const char* tzDirBackup = std::getenv("TZDIR");
- if (tzDirBackup != nullptr) {
+ const char* tzDir = std::getenv("TZDIR");
+ std::string tzDirBackup;
+ if (tzDir != nullptr) {
+ // std::string creates a deepcopy of buffer, which avoids that
+ // unsetting environment variable wrecks pointer to tzDir
+ tzDirBackup = tzDir;
ASSERT_TRUE(delEnv("TZDIR"));
}
ASSERT_TRUE(setEnv("TZDIR", "/path/to/wrong/tzdb"));
EXPECT_THAT([]() { getTimezoneByName("America/Los_Angeles"); },
testing::ThrowsMessage<TimezoneError>(testing::HasSubstr(
"Time zone file /path/to/wrong/tzdb/America/Los_Angeles
does not exist."
" Please install IANA time zone database and set TZDIR
env.")));
- if (tzDirBackup != nullptr) {
- ASSERT_TRUE(setEnv("TZDIR", tzDirBackup));
+ if (!tzDirBackup.empty()) {
+ ASSERT_TRUE(setEnv("TZDIR", tzDirBackup.c_str()));
} else {
ASSERT_TRUE(delEnv("TZDIR"));
}
}
+ TEST(TestTimezone, testTzdbFromCondaEnv) {
+ const char* tzDir = std::getenv("TZDIR");
+ // test only makes sense if TZDIR exists
+ if (tzDir != nullptr) {
+ std::string tzDirBackup = tzDir;
+ ASSERT_TRUE(delEnv("TZDIR"));
+
+ // remove "/share/zoneinfo" from TZDIR (as set through TZDATA_DIR in CI)
to
+ // get the equivalent of CONDA_PREFIX, relative to the location of the
tzdb
+ std::string condaPrefix(tzDirBackup);
+ condaPrefix += "/../..";
+ ASSERT_TRUE(setEnv("CONDA_PREFIX", condaPrefix.c_str()));
+
+ // small test sample to ensure tzbd loads with CONDA_PREFIX, even
without TZDIR
+ const Timezone* zrh = &getTimezoneByName("Europe/Zurich");
+ EXPECT_EQ("CET", getVariantFromZone(*zrh, "2024-03-31 00:59:59"));
+ EXPECT_EQ("CEST", getVariantFromZone(*zrh, "2024-03-31 01:00:00"));
+ EXPECT_EQ("CEST", getVariantFromZone(*zrh, "2024-10-26 23:59:59"));
+ EXPECT_EQ("CET", getVariantFromZone(*zrh, "2024-10-27 01:00:00"));
Review Comment:
This initially looked like an inconsistency in `getVariantFromZone`, at
least w.r.t. how the testing is done for Los Angeles / New York. In particular,
in the switch from daylight savings time (DST) to standard time (STD), the time
from 02:00-02:59am is passed twice, first as the last hour of DST, and then as
the first hour of STD.
Strictly speaking it is well-defined (in terms of UTC), which is the last
minute of DST before passing to STD, so I'll match this here as well. What I
ended up stumbling over is that current DST changes always happen between 2am
and 3am, whereas the DST change in 1974 in the US
[happened](https://www.timeanddate.com/time/change/usa/los-angeles?year=1974)
from 1am to 2am.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]