Commit 6275e7e2 authored by Vasili Skurydzin's avatar Vasili Skurydzin Committed by Commit Bot

Aix: Fix UTC time offset calculation with --no-icu-timezone-data flag

Change-Id: I3b504d7d22da475b317f5877bc0a5a642017754f
Reviewed-on: https://chromium-review.googlesource.com/c/1363531Reviewed-by: 's avatarJunliang Yan <jyan@ca.ibm.com>
Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Junliang Yan <jyan@ca.ibm.com>
Cr-Commit-Position: refs/heads/master@{#58109}
parent 62d3ea84
...@@ -36,6 +36,20 @@ namespace v8 { ...@@ -36,6 +36,20 @@ namespace v8 {
namespace base { namespace base {
int64_t get_gmt_offset(const tm& localtm) {
// replacement for tm->tm_gmtoff field in glibc
// returns seconds east of UTC, taking DST into account
struct timeval tv;
struct timezone tz;
int ret_code = gettimeofday(&tv, &tz);
// 0 = success, -1 = failure
DCHECK_NE(ret_code, -1);
if (ret_code == -1) {
return 0;
}
return (-tz.tz_minuteswest * 60) + (localtm.tm_isdst > 0 ? 3600 : 0);
}
class AIXTimezoneCache : public PosixTimezoneCache { class AIXTimezoneCache : public PosixTimezoneCache {
const char* LocalTimezone(double time) override; const char* LocalTimezone(double time) override;
...@@ -54,13 +68,15 @@ const char* AIXTimezoneCache::LocalTimezone(double time_ms) { ...@@ -54,13 +68,15 @@ const char* AIXTimezoneCache::LocalTimezone(double time_ms) {
} }
double AIXTimezoneCache::LocalTimeOffset(double time_ms, bool is_utc) { double AIXTimezoneCache::LocalTimeOffset(double time_ms, bool is_utc) {
// On AIX, struct tm does not contain a tm_gmtoff field. // On AIX, struct tm does not contain a tm_gmtoff field, use get_gmt_offset
// helper function
time_t utc = time(nullptr); time_t utc = time(nullptr);
DCHECK_NE(utc, -1); DCHECK_NE(utc, -1);
struct tm tm; struct tm tm;
struct tm* loc = localtime_r(&utc, &tm); struct tm* loc = localtime_r(&utc, &tm);
DCHECK_NOT_NULL(loc); DCHECK_NOT_NULL(loc);
return static_cast<double>((mktime(loc) - utc) * msPerSecond); return static_cast<double>(get_gmt_offset(*loc) * msPerSecond -
(loc->tm_isdst > 0 ? 3600 * msPerSecond : 0));
} }
TimezoneCache* OS::CreateTimezoneCache() { return new AIXTimezoneCache(); } TimezoneCache* OS::CreateTimezoneCache() { return new AIXTimezoneCache(); }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment