Add regression test for http://b/31938693.

Bug: http://b/31938693
Bug: https://code.google.com/p/android/issues/detail?id=225132
Test: this is a test
Change-Id: I858962a1dcd56d555a4836a7bfbdf92d5c3042f6
diff --git a/tests/time_test.cpp b/tests/time_test.cpp
index 2a46d8b..914cb61 100644
--- a/tests/time_test.cpp
+++ b/tests/time_test.cpp
@@ -628,3 +628,49 @@
   in.tv_nsec = 0;
   ASSERT_EQ(EINVAL, clock_nanosleep(CLOCK_THREAD_CPUTIME_ID, 0, &in, nullptr));
 }
+
+TEST(time, bug_31938693) {
+  // User-visible symptoms in N:
+  // http://b/31938693
+  // https://code.google.com/p/android/issues/detail?id=225132
+
+  // Actual underlying bug (the code change, not the tzdata upgrade that first exposed the bug):
+  // http://b/31848040
+
+  // This isn't a great test, because very few time zones were actually affected, and there's
+  // no real logic to which ones were affected: it was just a coincidence of the data that came
+  // after them in the tzdata file.
+
+  time_t t = 1475619727;
+  struct tm tm;
+
+  setenv("TZ", "America/Los_Angeles", 1);
+  tzset();
+  ASSERT_TRUE(localtime_r(&t, &tm) != nullptr);
+  EXPECT_EQ(15, tm.tm_hour);
+
+  setenv("TZ", "Europe/London", 1);
+  tzset();
+  ASSERT_TRUE(localtime_r(&t, &tm) != nullptr);
+  EXPECT_EQ(23, tm.tm_hour);
+
+  setenv("TZ", "America/Atka", 1);
+  tzset();
+  ASSERT_TRUE(localtime_r(&t, &tm) != nullptr);
+  EXPECT_EQ(13, tm.tm_hour);
+
+  setenv("TZ", "Pacific/Apia", 1);
+  tzset();
+  ASSERT_TRUE(localtime_r(&t, &tm) != nullptr);
+  EXPECT_EQ(12, tm.tm_hour);
+
+  setenv("TZ", "Pacific/Honolulu", 1);
+  tzset();
+  ASSERT_TRUE(localtime_r(&t, &tm) != nullptr);
+  EXPECT_EQ(12, tm.tm_hour);
+
+  setenv("TZ", "Asia/Magadan", 1);
+  tzset();
+  ASSERT_TRUE(localtime_r(&t, &tm) != nullptr);
+  EXPECT_EQ(9, tm.tm_hour);
+}