// https://www.ibm.com/support/pages/managing-time-zone-variable-posix
if (const char* env = std::getenv("TZ"))
{
- string_view s(env);
- if (s == "GMT0")
- s = "Etc/GMT";
- else if (s.size() == 4 && s[3] == '0')
- s = "Etc/UTC";
-
- // This will fail unless TZ contains an IANA time zone name,
- // or one of the special cases above.
- if (auto tz = do_locate_zone(this->zones, this->links, s))
+ // This will fail unless TZ contains an IANA time zone name.
+ if (auto tz = do_locate_zone(this->zones, this->links, env))
return tz;
}
#endif
+ // Default to UTC.
+ if (auto tz = do_locate_zone(this->zones, this->links, "UTC"))
+ return tz;
+
__throw_runtime_error("tzdb: cannot determine current zone");
}
// { dg-options "-std=gnu++20" }
// { dg-do run { target c++20 } }
// { dg-require-effective-target cxx11_abi }
-// { dg-additional-options "-DHAVE_TZDB" { target tzdb } }
#include <chrono>
#include <testsuite_hooks.h>
const tzdb& db = get_tzdb();
VERIFY( &db == &get_tzdb_list().front() );
-#ifdef HAVE_TZDB
- VERIFY( db.version == remote_version() );
- const tzdb& reloaded = reload_tzdb();
- if (reloaded.version == db.version)
- VERIFY( &reloaded == &db );
-#endif
+ const char* func;
+ try {
+ func = "remote_version";
+ VERIFY( db.version == remote_version() );
+ func = "reload_tzdb";
+ const tzdb& reloaded = reload_tzdb();
+ if (reloaded.version == db.version)
+ VERIFY( &reloaded == &db );
+ } catch (const std::exception&) {
+ std::printf("std::chrono::%s() failed\n", func);
+ }
}
void
test_current()
{
-#ifdef HAVE_TZDB
const tzdb& db = get_tzdb();
const time_zone* tz = db.current_zone();
VERIFY( tz == std::chrono::current_zone() );
-#endif
}
void
VERIFY( tz == db.locate_zone("Etc/GMT") );
VERIFY( tz == db.locate_zone("Etc/GMT+0") );
-#ifdef HAVE_TZDB
VERIFY( db.locate_zone(db.current_zone()->name()) == db.current_zone() );
-#endif
}
int main()