From d1c28a361b66f8a131fc277df455cb6835a5327e Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Fri, 13 Nov 2015 08:38:48 -0800 Subject: [PATCH] Improve libc time zone fallback behavior. We should fall back to GMT if neither the environment variable nor the system property is set. This is the case if you wipe a WiFi-only device, because we currently only take the time zone from cell networks. Bug: http://b/24773112 Change-Id: I90d236d4d492b6562d75021bd312030b91c1e298 --- libc/tzcode/localtime.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libc/tzcode/localtime.c b/libc/tzcode/localtime.c index cb8aeed46..b1ebb24cc 100644 --- a/libc/tzcode/localtime.c +++ b/libc/tzcode/localtime.c @@ -1316,9 +1316,10 @@ static void tzset_unlocked(void) { #if defined(__ANDROID__) + // The TZ environment variable is meant to override the system-wide setting. const char * name = getenv("TZ"); - // Try the "persist.sys.timezone" system property. + // If that's not set, look at the "persist.sys.timezone" system property. if (name == NULL) { static const prop_info *pi; @@ -1340,6 +1341,10 @@ tzset_unlocked(void) } } + // If that's not available (because you're running AOSP on a WiFi-only + // device, say), fall back to GMT. + if (name == NULL) name = gmt; + tzsetlcl(name); #else tzsetlcl(getenv("TZ"));