diff options
author | Abseil Team <absl-team@google.com> | 2021-11-30 04:52:52 (GMT) |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2021-11-30 04:53:29 (GMT) |
commit | bb9216085fbbf193408653ced9e73c61e7766e80 (patch) | |
tree | d23b2ca2cd2622a35bc091d1c6a86bc7d885989b | |
parent | e2f3978937c0244508135f126e2617a7734a68be (diff) | |
download | googletest-bb9216085fbbf193408653ced9e73c61e7766e80.zip googletest-bb9216085fbbf193408653ced9e73c61e7766e80.tar.gz googletest-bb9216085fbbf193408653ced9e73c61e7766e80.tar.bz2 |
Work around Android KitKat tzset bug
On KitKat, calling tzset with UTC+nn doesn't initialize all the
timezone state. If the previous timezone was something like
America/Chicago, then changing it to UTC+nn might have no effect.
Setting the timezone to an intermediate value like "UTC" avoids the
problem.
Works around https://github.com/android/ndk/issues/1604.
PiperOrigin-RevId: 413050236
Change-Id: I99b2d3330ae68f1d58cd2ca278d3eaae30bd1e83
-rw-r--r-- | googletest/test/gtest_unittest.cc | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index c079f46..6b2632a 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -450,6 +450,12 @@ class FormatEpochTimeInMillisAsIso8601Test : public Test { tzset(); GTEST_DISABLE_MSC_WARNINGS_POP_() #else +#if GTEST_OS_LINUX_ANDROID && __ANDROID_API__ < 21 + // Work around KitKat bug in tzset by setting "UTC" before setting "UTC+00". + // See https://github.com/android/ndk/issues/1604. + setenv("TZ", "UTC", 1); + tzset(); +#endif if (time_zone) { setenv(("TZ"), time_zone, 1); } else { |