Ignore invalid TZ settings in tests

For portability, absl_time_test builds a small, incomplete tzdata
database into the test binary and uses that instead of the system tzdata
database. (absl_time_test needs to run on some platforms that lack a
system tzdata database.) However, this causes issues if TZ is set to
something that isn’t in the test database. To address them, fall back to
America/Los_Angeles if TZ is set to an unknown value during testing.

Bug: https://bugs.debian.org/1012194
PiperOrigin-RevId: 453257912
Change-Id: I293d0f96876b31c32a2847468a3377bb49f3aa15
diff --git a/absl/time/internal/test_util.cc b/absl/time/internal/test_util.cc
index 9a485a0..24cff13 100644
--- a/absl/time/internal/test_util.cc
+++ b/absl/time/internal/test_util.cc
@@ -17,6 +17,7 @@
 #include <algorithm>
 #include <cstddef>
 #include <cstring>
+#include <memory>
 
 #include "absl/base/config.h"
 #include "absl/base/internal/raw_logging.h"
@@ -103,6 +104,12 @@
   const char* const end_;
 };
 
+std::unique_ptr<cctz::ZoneInfoSource> EmbeddedTestZone(const char* data,
+                                                       std::size_t size) {
+  return std::unique_ptr<cctz::ZoneInfoSource>(
+      new TestZoneInfoSource(data, size));
+}
+
 std::unique_ptr<cctz::ZoneInfoSource> TestFactory(
     const std::string& name,
     const std::function<std::unique_ptr<cctz::ZoneInfoSource>(
@@ -110,12 +117,14 @@
   for (const ZoneInfo& zoneinfo : kZoneInfo) {
     if (name == zoneinfo.name) {
       if (zoneinfo.data == nullptr) return nullptr;
-      return std::unique_ptr<cctz::ZoneInfoSource>(
-          new TestZoneInfoSource(zoneinfo.data, zoneinfo.length));
+      return EmbeddedTestZone(zoneinfo.data, zoneinfo.length);
     }
   }
-  ABSL_RAW_LOG(FATAL, "Unexpected time zone \"%s\" in test", name.c_str());
-  return nullptr;
+
+  // The embedded tzdata database knows nothing about this zone. Return
+  // something so the tests can proceed.
+  return EmbeddedTestZone(reinterpret_cast<char*>(America_Los_Angeles),
+                          America_Los_Angeles_len);
 }
 
 }  // namespace