Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
zhztheplayer committed Sep 10, 2024
1 parent 1b64d39 commit df0ae7d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions velox/type/tz/TimeZoneMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ inline std::chrono::minutes getTimeZoneOffset(int16_t tzID) {
return std::chrono::minutes{(tzID <= 840) ? (tzID - 841) : (tzID - 840)};
}

const date::time_zone* locateZoneExt(std::string_view tz_name) {
TestValue::adjust("facebook::velox::tz::locateZoneExt", &tz_name);
const date::time_zone* locateZoneImpl(std::string_view tz_name) {
TestValue::adjust("facebook::velox::tz::locateZoneImpl", &tz_name);
const date::time_zone* zone = date::locate_zone(tz_name);
return zone;
}
Expand All @@ -62,7 +62,7 @@ TTimeZoneDatabase buildTimeZoneDatabase(

if (entry.first == 0) {
timeZonePtr =
std::make_unique<TimeZone>("UTC", entry.first, locateZoneExt("UTC"));
std::make_unique<TimeZone>("UTC", entry.first, locateZoneImpl("UTC"));
} else if (entry.first <= 1680) {
std::chrono::minutes offset = getTimeZoneOffset(entry.first);
timeZonePtr =
Expand All @@ -73,9 +73,15 @@ TTimeZoneDatabase buildTimeZoneDatabase(
else {
const date::time_zone* zone;
try {
zone = locateZoneExt(entry.second);
zone = locateZoneImpl(entry.second);
} catch (date::invalid_timezone& err) {
// Timezone not found in OS, skip it.
// When this exception is thrown, it typically means the time zone name
// we are trying to locate cannot be found from OS's time zone database.
// Thus, we just command a "continue;" to skip the creation of the
// corresponding TimeZone object.
//
// Then, once this time zone is requested in runtime, a runtime error
// will be thrown and caller is expected to handle that error in code.
LOG(WARNING) << "Unable to load [" << entry.second
<< "] from local timezone database: " << err.what();
continue;
Expand Down
2 changes: 1 addition & 1 deletion velox/type/tz/tests/TimeZoneMapTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ TEST(TimeZoneMapTest, externalInvalid) {
const std::string testZone = "Africa/Abidjan";
common::testutil::TestValue::enable();
SCOPED_TESTVALUE_SET(
"facebook::velox::tz::locateZoneExt",
"facebook::velox::tz::locateZoneImpl",
std::function<void(std::string_view * tz_name)>(
[&](std::string_view* tz_name) -> void {
if (*tz_name == testZone) {
Expand Down

0 comments on commit df0ae7d

Please sign in to comment.