diff options
author | Ben Murdoch <benm@google.com> | 2010-02-11 17:40:47 +0000 |
---|---|---|
committer | Ben Murdoch <benm@google.com> | 2010-02-12 11:23:20 +0000 |
commit | 6b23cceca405474a281cdf61cbcd6ecf10944a82 (patch) | |
tree | 80175289e7123c6b550209ec0404515521752532 | |
parent | a2e4be91739723c8a0751d441c3e764af2009ccc (diff) | |
download | android_external_v8-6b23cceca405474a281cdf61cbcd6ecf10944a82.tar.gz android_external_v8-6b23cceca405474a281cdf61cbcd6ecf10944a82.tar.bz2 android_external_v8-6b23cceca405474a281cdf61cbcd6ecf10944a82.zip |
Add Android workaround for calculating the timezone UTC offset as on Android, we do not have the tm_gmtoff field of tm.
BUG=2093202
Change-Id: Icbcbe629322b109327390bd28114c6329ea0e351
-rw-r--r-- | src/platform-linux.cc | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/platform-linux.cc b/src/platform-linux.cc index 005b1deb..247f43f8 100644 --- a/src/platform-linux.cc +++ b/src/platform-linux.cc @@ -169,11 +169,29 @@ const char* OS::LocalTimezone(double time) { double OS::LocalTimeOffset() { +#if defined(ANDROID) + // Android does not have tm_gmtoff, so instead we'll work it out. + // Use a date in the local timezone representing 1st January 2010. + struct tm t; + t.tm_sec = 0; + t.tm_min = 0; + t.tm_hour = 0; + t.tm_mday = 1; + t.tm_mon = 0; + t.tm_year = 110; + t.tm_wday = 0; + t.tm_yday = 0; + t.tm_isdst = 0; + // 1262304000 is January, 1 2010 UTC. + time_t offset = 1262304000 - mktime(&t); + return static_cast<double>(offset * msPerSecond); +#else time_t tv = time(NULL); struct tm* t = localtime(&tv); // tm_gmtoff includes any daylight savings offset, so subtract it. return static_cast<double>(t->tm_gmtoff * msPerSecond - (t->tm_isdst > 0 ? 3600 * msPerSecond : 0)); +#endif } |