From d98230a0777c8b87f7a0c9c38a8bd1abb91ef80e Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Wed, 10 Apr 2024 15:30:40 +1100 Subject: [PATCH 01/20] find tzdb without TZDIR when in conda-environments --- c++/src/Timezone.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/c++/src/Timezone.cc b/c++/src/Timezone.cc index fbad35fbcf..757a92874c 100644 --- a/c++/src/Timezone.cc +++ b/c++/src/Timezone.cc @@ -659,7 +659,15 @@ namespace orc { const char* getTimezoneDirectory() { const char* dir = getenv("TZDIR"); if (!dir) { - dir = DEFAULT_TZDIR; + // this is present if we're in an activated conda environment + const char* conda_prefix = getenv("CONDA_PREFIX"); + if (conda_prefix) { + std::string conda_dir(conda_prefix); + conda_dir += "/share/zoneinfo"; + dir = conda_dir.c_str(); + } else { + dir = DEFAULT_TZDIR; + } } return dir; } From 23b0d67e68005d09c0065b6734606719f56f9905 Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Wed, 10 Apr 2024 16:37:23 +1100 Subject: [PATCH 02/20] camelCase --- c++/src/Timezone.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/c++/src/Timezone.cc b/c++/src/Timezone.cc index 757a92874c..082b303c77 100644 --- a/c++/src/Timezone.cc +++ b/c++/src/Timezone.cc @@ -660,11 +660,11 @@ namespace orc { const char* dir = getenv("TZDIR"); if (!dir) { // this is present if we're in an activated conda environment - const char* conda_prefix = getenv("CONDA_PREFIX"); - if (conda_prefix) { - std::string conda_dir(conda_prefix); - conda_dir += "/share/zoneinfo"; - dir = conda_dir.c_str(); + const char* condaPrefix = getenv("CONDA_PREFIX"); + if (condaPrefix) { + std::string condaDir(condaPrefix); + condaDir += "/share/zoneinfo"; + dir = condaDir.c_str(); } else { dir = DEFAULT_TZDIR; } From f0b4951b7cd4df9a2b5c9fe0fd4230b05c787f5a Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Wed, 10 Apr 2024 17:12:33 +1100 Subject: [PATCH 03/20] change getTimezoneDirectory to return std::string --- c++/src/Timezone.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/c++/src/Timezone.cc b/c++/src/Timezone.cc index 082b303c77..6edb9cdcdf 100644 --- a/c++/src/Timezone.cc +++ b/c++/src/Timezone.cc @@ -656,7 +656,7 @@ namespace orc { epoch_ = utcEpoch - getVariant(utcEpoch).gmtOffset; } - const char* getTimezoneDirectory() { + std::string getTimezoneDirectory() { const char* dir = getenv("TZDIR"); if (!dir) { // this is present if we're in an activated conda environment @@ -664,12 +664,13 @@ namespace orc { if (condaPrefix) { std::string condaDir(condaPrefix); condaDir += "/share/zoneinfo"; - dir = condaDir.c_str(); + return condaDir; } else { dir = DEFAULT_TZDIR; } } - return dir; + std::string tzDir(dir); + return tzDir; } /** From 47fbefda95fb86ee12bf62898d2e687124bc7601 Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Wed, 10 Apr 2024 18:44:59 +1100 Subject: [PATCH 04/20] add test for discovering tzdata via CONDA_PREFIX --- c++/test/TestTimezone.cc | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/c++/test/TestTimezone.cc b/c++/test/TestTimezone.cc index 2330fcfb04..fd64fd68a4 100644 --- a/c++/test/TestTimezone.cc +++ b/c++/test/TestTimezone.cc @@ -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())); + + // 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 From d523ca5eb5b5208250c12cec8de707e188d9eff9 Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Wed, 10 Apr 2024 18:48:27 +1100 Subject: [PATCH 05/20] missing semicola --- c++/test/TestTimezone.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/c++/test/TestTimezone.cc b/c++/test/TestTimezone.cc index fd64fd68a4..6b7a2d984c 100644 --- a/c++/test/TestTimezone.cc +++ b/c++/test/TestTimezone.cc @@ -444,8 +444,8 @@ namespace orc { ASSERT_TRUE(delEnv("TZDIR")); // remove "/share/zoneinfo" from TZDIR to get (equivalent of) CONDA_PREFIX - std::string condaPrefix(tzDirBackup) - condaPrefix += "/../.." + std::string condaPrefix(tzDirBackup); + condaPrefix += "/../.."; ASSERT_TRUE(setEnv("CONDA_PREFIX", condaPrefix.c_str())); // small sample to ensure tzbd loads correctly with CONDA_PREFIX, even without TZDIR From 65338585e91f1b4e2d7b2bc792c71ad9445402a0 Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Wed, 10 Apr 2024 19:05:40 +1100 Subject: [PATCH 06/20] delete TZDIR only after populating CONDA_PREFIX --- c++/test/TestTimezone.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/c++/test/TestTimezone.cc b/c++/test/TestTimezone.cc index 6b7a2d984c..0dcc7ef182 100644 --- a/c++/test/TestTimezone.cc +++ b/c++/test/TestTimezone.cc @@ -441,14 +441,14 @@ namespace orc { 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 + // remove "/share/zoneinfo" from TZDIR (as set through TZDATA_DIR) 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 sample to ensure tzbd loads correctly with CONDA_PREFIX, even without TZDIR + ASSERT_TRUE(delEnv("TZDIR")); const Timezone* la1 = &getTimezoneByName("America/Los_Angeles"); const Timezone* la2 = &getTimezoneByName("America/Los_Angeles"); EXPECT_EQ(la1, la2); From ad2fcee175175fba13439ebb0c9529467da6af5e Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Wed, 10 Apr 2024 19:58:46 +1100 Subject: [PATCH 07/20] deepcopy tzDirBackup before deleting underlying environment variable --- c++/test/TestTimezone.cc | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/c++/test/TestTimezone.cc b/c++/test/TestTimezone.cc index 0dcc7ef182..48c24601d6 100644 --- a/c++/test/TestTimezone.cc +++ b/c++/test/TestTimezone.cc @@ -420,9 +420,20 @@ namespace orc { #endif } + char * deepcopy(const char* name) { + // this allocates a new buffer that must be freed after use +#ifdef _MSC_VER + return _strdup(name); +#else + return strdup(name); +#endif + } + TEST(TestTimezone, testMissingTZDB) { - const char* tzDirBackup = std::getenv("TZDIR"); - if (tzDirBackup != nullptr) { + const char* tzDir = std::getenv("TZDIR"); + char* tzDirBackup = nullptr; + if (tzDir != nullptr) { + tzDirBackup = deepcopy(tzDir); ASSERT_TRUE(delEnv("TZDIR")); } ASSERT_TRUE(setEnv("TZDIR", "/path/to/wrong/tzdb")); @@ -432,15 +443,17 @@ namespace orc { " Please install IANA time zone database and set TZDIR env."))); if (tzDirBackup != nullptr) { ASSERT_TRUE(setEnv("TZDIR", tzDirBackup)); + free(tzDirBackup); } else { ASSERT_TRUE(delEnv("TZDIR")); } } TEST(TestTimezone, testTzdbFromCondaEnv) { - const char* tzDirBackup = std::getenv("TZDIR"); + const char* tzDir = std::getenv("TZDIR"); // test only makes sense if TZDIR exists - if (tzDirBackup != nullptr) { + if (tzDir != nullptr) { + char* tzDirBackup = deepcopy(tzDir); // remove "/share/zoneinfo" from TZDIR (as set through TZDATA_DIR) to get // the equivalent of CONDA_PREFIX, relative to the location of the tzdb std::string condaPrefix(tzDirBackup); @@ -459,6 +472,7 @@ namespace orc { ASSERT_TRUE(delEnv("CONDA_PREFIX")); ASSERT_TRUE(setEnv("TZDIR", tzDirBackup)); + free(tzDirBackup); } } From a3a022434b10ab976bdb23ea2db8ff935ab830bd Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Wed, 10 Apr 2024 20:43:17 +1100 Subject: [PATCH 08/20] move removal of TZDIR env var to accustomed place, now that backup works --- c++/test/TestTimezone.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/c++/test/TestTimezone.cc b/c++/test/TestTimezone.cc index 48c24601d6..d1c619f136 100644 --- a/c++/test/TestTimezone.cc +++ b/c++/test/TestTimezone.cc @@ -454,6 +454,8 @@ namespace orc { // test only makes sense if TZDIR exists if (tzDir != nullptr) { char* tzDirBackup = deepcopy(tzDir); + ASSERT_TRUE(delEnv("TZDIR")); + // remove "/share/zoneinfo" from TZDIR (as set through TZDATA_DIR) to get // the equivalent of CONDA_PREFIX, relative to the location of the tzdb std::string condaPrefix(tzDirBackup); @@ -461,7 +463,6 @@ namespace orc { ASSERT_TRUE(setEnv("CONDA_PREFIX", condaPrefix.c_str())); // small sample to ensure tzbd loads correctly with CONDA_PREFIX, even without TZDIR - ASSERT_TRUE(delEnv("TZDIR")); const Timezone* la1 = &getTimezoneByName("America/Los_Angeles"); const Timezone* la2 = &getTimezoneByName("America/Los_Angeles"); EXPECT_EQ(la1, la2); From 67ad1593798d88ce8555747e4c8eb0627498866c Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Wed, 10 Apr 2024 20:43:35 +1100 Subject: [PATCH 09/20] fix formatting nit --- c++/test/TestTimezone.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/c++/test/TestTimezone.cc b/c++/test/TestTimezone.cc index d1c619f136..0753f8050f 100644 --- a/c++/test/TestTimezone.cc +++ b/c++/test/TestTimezone.cc @@ -420,7 +420,7 @@ namespace orc { #endif } - char * deepcopy(const char* name) { + char* deepcopy(const char* name) { // this allocates a new buffer that must be freed after use #ifdef _MSC_VER return _strdup(name); From 9c68f868f7e0555fd50f2c4e8ac171f8b479e352 Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Wed, 10 Apr 2024 20:45:21 +1100 Subject: [PATCH 10/20] add comment about why we deepcopy --- c++/test/TestTimezone.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/c++/test/TestTimezone.cc b/c++/test/TestTimezone.cc index 0753f8050f..34ab8f6943 100644 --- a/c++/test/TestTimezone.cc +++ b/c++/test/TestTimezone.cc @@ -433,6 +433,7 @@ namespace orc { const char* tzDir = std::getenv("TZDIR"); char* tzDirBackup = nullptr; if (tzDir != nullptr) { + // avoid that unsetting environment variable wrecks pointer to tzDir tzDirBackup = deepcopy(tzDir); ASSERT_TRUE(delEnv("TZDIR")); } From e05a0c1e98d12664bcddf8ceeff3b691eefba6eb Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Wed, 10 Apr 2024 21:12:14 +1100 Subject: [PATCH 11/20] test that CONDA_PREFIX with backslashes passes as well --- c++/test/TestTimezone.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/c++/test/TestTimezone.cc b/c++/test/TestTimezone.cc index 34ab8f6943..9a4f1e15bd 100644 --- a/c++/test/TestTimezone.cc +++ b/c++/test/TestTimezone.cc @@ -22,6 +22,7 @@ #include "wrap/gtest-wrapper.h" #include +#include #include #include @@ -472,6 +473,17 @@ namespace orc { EXPECT_EQ("PDT", getVariantFromZone(*la1, "1974-10-27 08:59:59")); EXPECT_EQ("PST", getVariantFromZone(*la1, "1974-10-27 09:00:00")); + // CONDA_PREFIX contains backslashes on windows; test that this doesn't blow up + std::replace(condaPrefix.begin(), condaPrefix.end(), '/', '\\'); + ASSERT_TRUE(setEnv("CONDA_PREFIX", condaPrefix.c_str())); + 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)); free(tzDirBackup); From 71eeed306d91a5950c248cceb86c07e8aad27e80 Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Wed, 10 Apr 2024 21:37:58 +1100 Subject: [PATCH 12/20] do not reuse variables incorrectly in testTzdbFromCondaEnv --- c++/test/TestTimezone.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/c++/test/TestTimezone.cc b/c++/test/TestTimezone.cc index 9a4f1e15bd..241f27b11f 100644 --- a/c++/test/TestTimezone.cc +++ b/c++/test/TestTimezone.cc @@ -476,13 +476,13 @@ namespace orc { // CONDA_PREFIX contains backslashes on windows; test that this doesn't blow up std::replace(condaPrefix.begin(), condaPrefix.end(), '/', '\\'); ASSERT_TRUE(setEnv("CONDA_PREFIX", condaPrefix.c_str())); - 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")); + const Timezone* la3 = &getTimezoneByName("America/Los_Angeles"); + const Timezone* la4 = &getTimezoneByName("America/Los_Angeles"); + EXPECT_EQ(la3, la4); + EXPECT_EQ("PST", getVariantFromZone(*la3, "1974-01-06 09:59:59")); + EXPECT_EQ("PDT", getVariantFromZone(*la3, "1974-01-06 10:00:00")); + EXPECT_EQ("PDT", getVariantFromZone(*la3, "1974-10-27 08:59:59")); + EXPECT_EQ("PST", getVariantFromZone(*la3, "1974-10-27 09:00:00")); ASSERT_TRUE(delEnv("CONDA_PREFIX")); ASSERT_TRUE(setEnv("TZDIR", tzDirBackup)); From 65ddf0d9ff2c058c11f13bedbd1178aa478765fe Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Wed, 10 Apr 2024 21:41:52 +1100 Subject: [PATCH 13/20] minor cosmetics --- c++/test/TestTimezone.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/c++/test/TestTimezone.cc b/c++/test/TestTimezone.cc index 241f27b11f..781a8f2087 100644 --- a/c++/test/TestTimezone.cc +++ b/c++/test/TestTimezone.cc @@ -21,8 +21,8 @@ #include "wrap/gmock.h" #include "wrap/gtest-wrapper.h" -#include #include +#include #include #include @@ -458,13 +458,13 @@ namespace orc { char* tzDirBackup = deepcopy(tzDir); ASSERT_TRUE(delEnv("TZDIR")); - // remove "/share/zoneinfo" from TZDIR (as set through TZDATA_DIR) to get - // the equivalent of CONDA_PREFIX, relative to the location of the tzdb + // 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 sample to ensure tzbd loads correctly with CONDA_PREFIX, even without TZDIR + // small test sample to ensure tzbd loads with CONDA_PREFIX, even without TZDIR const Timezone* la1 = &getTimezoneByName("America/Los_Angeles"); const Timezone* la2 = &getTimezoneByName("America/Los_Angeles"); EXPECT_EQ(la1, la2); @@ -476,6 +476,8 @@ namespace orc { // CONDA_PREFIX contains backslashes on windows; test that this doesn't blow up std::replace(condaPrefix.begin(), condaPrefix.end(), '/', '\\'); ASSERT_TRUE(setEnv("CONDA_PREFIX", condaPrefix.c_str())); + + // as above const Timezone* la3 = &getTimezoneByName("America/Los_Angeles"); const Timezone* la4 = &getTimezoneByName("America/Los_Angeles"); EXPECT_EQ(la3, la4); @@ -484,6 +486,7 @@ namespace orc { EXPECT_EQ("PDT", getVariantFromZone(*la3, "1974-10-27 08:59:59")); EXPECT_EQ("PST", getVariantFromZone(*la3, "1974-10-27 09:00:00")); + // restore state of environment variables ASSERT_TRUE(delEnv("CONDA_PREFIX")); ASSERT_TRUE(setEnv("TZDIR", tzDirBackup)); free(tzDirBackup); From 04934f674302e8e615e44668f6ada23031c27769 Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Thu, 11 Apr 2024 06:46:55 +1100 Subject: [PATCH 14/20] incorporate review feedback --- c++/src/Timezone.cc | 3 +-- c++/test/TestTimezone.cc | 24 +++++++----------------- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/c++/src/Timezone.cc b/c++/src/Timezone.cc index 6edb9cdcdf..9ab7638188 100644 --- a/c++/src/Timezone.cc +++ b/c++/src/Timezone.cc @@ -669,8 +669,7 @@ namespace orc { dir = DEFAULT_TZDIR; } } - std::string tzDir(dir); - return tzDir; + return dir; } /** diff --git a/c++/test/TestTimezone.cc b/c++/test/TestTimezone.cc index 781a8f2087..2f56da4c5e 100644 --- a/c++/test/TestTimezone.cc +++ b/c++/test/TestTimezone.cc @@ -421,21 +421,13 @@ namespace orc { #endif } - char* deepcopy(const char* name) { - // this allocates a new buffer that must be freed after use -#ifdef _MSC_VER - return _strdup(name); -#else - return strdup(name); -#endif - } - TEST(TestTimezone, testMissingTZDB) { const char* tzDir = std::getenv("TZDIR"); - char* tzDirBackup = nullptr; + std::string tzDirBackup = nullptr; if (tzDir != nullptr) { - // avoid that unsetting environment variable wrecks pointer to tzDir - tzDirBackup = deepcopy(tzDir); + // 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")); @@ -444,8 +436,7 @@ namespace orc { "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)); - free(tzDirBackup); + ASSERT_TRUE(setEnv("TZDIR", tzDirBackup.c_str())); } else { ASSERT_TRUE(delEnv("TZDIR")); } @@ -455,7 +446,7 @@ namespace orc { const char* tzDir = std::getenv("TZDIR"); // test only makes sense if TZDIR exists if (tzDir != nullptr) { - char* tzDirBackup = deepcopy(tzDir); + std::string tzDirBackup = tzDir; ASSERT_TRUE(delEnv("TZDIR")); // remove "/share/zoneinfo" from TZDIR (as set through TZDATA_DIR in CI) to @@ -488,8 +479,7 @@ namespace orc { // restore state of environment variables ASSERT_TRUE(delEnv("CONDA_PREFIX")); - ASSERT_TRUE(setEnv("TZDIR", tzDirBackup)); - free(tzDirBackup); + ASSERT_TRUE(setEnv("TZDIR", tzDirBackup.c_str())); } } From 49da6509a1406a893679396aca45825859241ea0 Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Thu, 11 Apr 2024 13:44:53 +1100 Subject: [PATCH 15/20] fix std::string comparison --- c++/test/TestTimezone.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/c++/test/TestTimezone.cc b/c++/test/TestTimezone.cc index 2f56da4c5e..935434dec5 100644 --- a/c++/test/TestTimezone.cc +++ b/c++/test/TestTimezone.cc @@ -423,7 +423,7 @@ namespace orc { TEST(TestTimezone, testMissingTZDB) { const char* tzDir = std::getenv("TZDIR"); - std::string tzDirBackup = nullptr; + std::string tzDirBackup; if (tzDir != nullptr) { // std::string creates a deepcopy of buffer, which avoids that // unsetting environment variable wrecks pointer to tzDir @@ -435,7 +435,7 @@ namespace orc { testing::ThrowsMessage(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) { + if (!tzDirBackup.empty()) { ASSERT_TRUE(setEnv("TZDIR", tzDirBackup.c_str())); } else { ASSERT_TRUE(delEnv("TZDIR")); From 61de6c674ca971f987378daff6be8e5e7729f6b8 Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Thu, 11 Apr 2024 14:36:39 +1100 Subject: [PATCH 16/20] use different timezones to avoid caching effects --- c++/test/TestTimezone.cc | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/c++/test/TestTimezone.cc b/c++/test/TestTimezone.cc index 935434dec5..a3379f4fc0 100644 --- a/c++/test/TestTimezone.cc +++ b/c++/test/TestTimezone.cc @@ -456,26 +456,22 @@ namespace orc { ASSERT_TRUE(setEnv("CONDA_PREFIX", condaPrefix.c_str())); // small test sample to ensure tzbd loads 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")); + const Timezone* zrh = &getTimezoneByName("Europe/Zurich"); + EXPECT_EQ("CET", getVariantFromZone(*zrh, "2024-03-31 01:59:59")); + EXPECT_EQ("CEST", getVariantFromZone(*zrh, "2024-03-31 02:00:00")); + EXPECT_EQ("CEST", getVariantFromZone(*zrh, "2024-10-27 00:59:59")); + EXPECT_EQ("CET", getVariantFromZone(*zrh, "2024-10-27 01:00:00")); // CONDA_PREFIX contains backslashes on windows; test that this doesn't blow up std::replace(condaPrefix.begin(), condaPrefix.end(), '/', '\\'); ASSERT_TRUE(setEnv("CONDA_PREFIX", condaPrefix.c_str())); // as above - const Timezone* la3 = &getTimezoneByName("America/Los_Angeles"); - const Timezone* la4 = &getTimezoneByName("America/Los_Angeles"); - EXPECT_EQ(la3, la4); - EXPECT_EQ("PST", getVariantFromZone(*la3, "1974-01-06 09:59:59")); - EXPECT_EQ("PDT", getVariantFromZone(*la3, "1974-01-06 10:00:00")); - EXPECT_EQ("PDT", getVariantFromZone(*la3, "1974-10-27 08:59:59")); - EXPECT_EQ("PST", getVariantFromZone(*la3, "1974-10-27 09:00:00")); + const Timezone* syd = &getTimezoneByName("Australia/Sydney"); + EXPECT_EQ("AEDT", getVariantFromZone(*syd, "2024-04-06 15:59:59")); + EXPECT_EQ("AEST", getVariantFromZone(*syd, "2024-04-06 16:00:00")); + EXPECT_EQ("AEST", getVariantFromZone(*syd, "2024-10-05 16:59:59")); + EXPECT_EQ("AEDT", getVariantFromZone(*syd, "2024-10-05 17:00:00")); // restore state of environment variables ASSERT_TRUE(delEnv("CONDA_PREFIX")); From f726050bad3cb0f4053305f59999a96fd6ae2786 Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Thu, 11 Apr 2024 15:04:28 +1100 Subject: [PATCH 17/20] off by an hour --- c++/test/TestTimezone.cc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/c++/test/TestTimezone.cc b/c++/test/TestTimezone.cc index a3379f4fc0..99f34913e2 100644 --- a/c++/test/TestTimezone.cc +++ b/c++/test/TestTimezone.cc @@ -457,10 +457,10 @@ namespace orc { // 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 01:59:59")); - EXPECT_EQ("CEST", getVariantFromZone(*zrh, "2024-03-31 02:00:00")); - EXPECT_EQ("CEST", getVariantFromZone(*zrh, "2024-10-27 00:59:59")); - EXPECT_EQ("CET", getVariantFromZone(*zrh, "2024-10-27 01:00:00")); + 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 00:00:00")); // CONDA_PREFIX contains backslashes on windows; test that this doesn't blow up std::replace(condaPrefix.begin(), condaPrefix.end(), '/', '\\'); @@ -468,10 +468,10 @@ namespace orc { // as above const Timezone* syd = &getTimezoneByName("Australia/Sydney"); - EXPECT_EQ("AEDT", getVariantFromZone(*syd, "2024-04-06 15:59:59")); - EXPECT_EQ("AEST", getVariantFromZone(*syd, "2024-04-06 16:00:00")); - EXPECT_EQ("AEST", getVariantFromZone(*syd, "2024-10-05 16:59:59")); - EXPECT_EQ("AEDT", getVariantFromZone(*syd, "2024-10-05 17:00:00")); + EXPECT_EQ("AEDT", getVariantFromZone(*syd, "2024-04-06 14:59:59")); + EXPECT_EQ("AEST", getVariantFromZone(*syd, "2024-04-06 15:00:00")); + EXPECT_EQ("AEST", getVariantFromZone(*syd, "2024-10-05 15:59:59")); + EXPECT_EQ("AEDT", getVariantFromZone(*syd, "2024-10-05 16:00:00")); // restore state of environment variables ASSERT_TRUE(delEnv("CONDA_PREFIX")); From 1d15ac72d012e11fd39176798076560c8b43b656 Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Thu, 11 Apr 2024 15:39:14 +1100 Subject: [PATCH 18/20] avoid times which (in local time) occur in both DST and then again in STD --- c++/test/TestTimezone.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/c++/test/TestTimezone.cc b/c++/test/TestTimezone.cc index 99f34913e2..c987110058 100644 --- a/c++/test/TestTimezone.cc +++ b/c++/test/TestTimezone.cc @@ -460,7 +460,7 @@ namespace orc { 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 00:00:00")); + EXPECT_EQ("CET", getVariantFromZone(*zrh, "2024-10-27 01:00:00")); // CONDA_PREFIX contains backslashes on windows; test that this doesn't blow up std::replace(condaPrefix.begin(), condaPrefix.end(), '/', '\\'); @@ -469,7 +469,7 @@ namespace orc { // as above const Timezone* syd = &getTimezoneByName("Australia/Sydney"); EXPECT_EQ("AEDT", getVariantFromZone(*syd, "2024-04-06 14:59:59")); - EXPECT_EQ("AEST", getVariantFromZone(*syd, "2024-04-06 15:00:00")); + EXPECT_EQ("AEST", getVariantFromZone(*syd, "2024-04-06 16:00:00")); EXPECT_EQ("AEST", getVariantFromZone(*syd, "2024-10-05 15:59:59")); EXPECT_EQ("AEDT", getVariantFromZone(*syd, "2024-10-05 16:00:00")); From 884cd79fc62191964e279daf0133de3ebae01aa7 Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Thu, 11 Apr 2024 16:43:15 +1100 Subject: [PATCH 19/20] catch the last minute of DST in testTzdbFromCondaEnv --- c++/test/TestTimezone.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/c++/test/TestTimezone.cc b/c++/test/TestTimezone.cc index c987110058..25cdc1297d 100644 --- a/c++/test/TestTimezone.cc +++ b/c++/test/TestTimezone.cc @@ -459,7 +459,7 @@ namespace orc { 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("CEST", getVariantFromZone(*zrh, "2024-10-27 00:59:59")); EXPECT_EQ("CET", getVariantFromZone(*zrh, "2024-10-27 01:00:00")); // CONDA_PREFIX contains backslashes on windows; test that this doesn't blow up @@ -468,7 +468,7 @@ namespace orc { // as above const Timezone* syd = &getTimezoneByName("Australia/Sydney"); - EXPECT_EQ("AEDT", getVariantFromZone(*syd, "2024-04-06 14:59:59")); + EXPECT_EQ("AEDT", getVariantFromZone(*syd, "2024-04-06 15:59:59")); EXPECT_EQ("AEST", getVariantFromZone(*syd, "2024-04-06 16:00:00")); EXPECT_EQ("AEST", getVariantFromZone(*syd, "2024-10-05 15:59:59")); EXPECT_EQ("AEDT", getVariantFromZone(*syd, "2024-10-05 16:00:00")); From 6d9ed1a64471ed350670e64782d361773f1910b3 Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Thu, 11 Apr 2024 17:41:15 +1100 Subject: [PATCH 20/20] improve comment --- c++/test/TestTimezone.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/c++/test/TestTimezone.cc b/c++/test/TestTimezone.cc index 25cdc1297d..727d6a2763 100644 --- a/c++/test/TestTimezone.cc +++ b/c++/test/TestTimezone.cc @@ -466,7 +466,7 @@ namespace orc { std::replace(condaPrefix.begin(), condaPrefix.end(), '/', '\\'); ASSERT_TRUE(setEnv("CONDA_PREFIX", condaPrefix.c_str())); - // as above + // as above, but different timezone to avoid hitting cache const Timezone* syd = &getTimezoneByName("Australia/Sydney"); EXPECT_EQ("AEDT", getVariantFromZone(*syd, "2024-04-06 15:59:59")); EXPECT_EQ("AEST", getVariantFromZone(*syd, "2024-04-06 16:00:00"));