Skip to content

Commit bb92160

Browse files
Abseil Teamcopybara-github
authored andcommitted
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 android/ndk#1604. PiperOrigin-RevId: 413050236 Change-Id: I99b2d3330ae68f1d58cd2ca278d3eaae30bd1e83
1 parent e2f3978 commit bb92160

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

googletest/test/gtest_unittest.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,12 @@ class FormatEpochTimeInMillisAsIso8601Test : public Test {
450450
tzset();
451451
GTEST_DISABLE_MSC_WARNINGS_POP_()
452452
#else
453+
#if GTEST_OS_LINUX_ANDROID && __ANDROID_API__ < 21
454+
// Work around KitKat bug in tzset by setting "UTC" before setting "UTC+00".
455+
// See https://github.com/android/ndk/issues/1604.
456+
setenv("TZ", "UTC", 1);
457+
tzset();
458+
#endif
453459
if (time_zone) {
454460
setenv(("TZ"), time_zone, 1);
455461
} else {

0 commit comments

Comments
 (0)