Commit fa4ec9fd authored by Jaideep Bajwa's avatar Jaideep Bajwa Committed by Commit Bot

[date] Refactor PosixTimezoneCache for different OS

Follow up on https://codereview.chromium.org/2740353002. Created
PosixDefaultTimezoneCache which is a subclass of PosixTimezoneCache
containing definition of LocalTimezone and LocalTimeOffset which is
separate for different OS.

R=littledan@chromium.org, ulan@chromium.org

BUG=v8:6578
LOG=N

Change-Id: I58342893aeefe79ac50e1df041d614fc473f15bf
Reviewed-on: https://chromium-review.googlesource.com/568686Reviewed-by: 's avatarDaniel Ehrenberg <littledan@chromium.org>
Commit-Queue: Jaideep Bajwa <bjaideep@ca.ibm.com>
Cr-Commit-Position: refs/heads/master@{#46604}
parent 36421dc4
......@@ -2455,6 +2455,8 @@ v8_component("v8_libbase") {
if (is_posix) {
sources += [
"src/base/platform/platform-posix-time.cc",
"src/base/platform/platform-posix-time.h",
"src/base/platform/platform-posix.cc",
"src/base/platform/platform-posix.h",
]
......
......@@ -29,13 +29,16 @@
#undef MAP_TYPE
#include "src/base/macros.h"
#include "src/base/platform/platform-posix-time.h"
#include "src/base/platform/platform-posix.h"
#include "src/base/platform/platform.h"
namespace v8 {
namespace base {
TimezoneCache* OS::CreateTimezoneCache() { return new PosixTimezoneCache(); }
TimezoneCache* OS::CreateTimezoneCache() {
return new PosixDefaultTimezoneCache();
}
void* OS::Allocate(const size_t requested, size_t* allocated,
OS::MemoryPermission access) {
......
......@@ -5,13 +5,16 @@
#include <sys/mman.h>
#include "src/base/macros.h"
#include "src/base/platform/platform-posix-time.h"
#include "src/base/platform/platform-posix.h"
#include "src/base/platform/platform.h"
namespace v8 {
namespace base {
TimezoneCache* OS::CreateTimezoneCache() { return new PosixTimezoneCache(); }
TimezoneCache* OS::CreateTimezoneCache() {
return new PosixDefaultTimezoneCache();
}
void* OS::Allocate(const size_t requested, size_t* allocated,
OS::MemoryPermission access) {
......
......@@ -44,6 +44,7 @@
#undef MAP_TYPE
#include "src/base/macros.h"
#include "src/base/platform/platform-posix-time.h"
#include "src/base/platform/platform-posix.h"
#include "src/base/platform/platform.h"
......@@ -92,7 +93,9 @@ bool OS::ArmUsingHardFloat() {
#endif // def __arm__
TimezoneCache* OS::CreateTimezoneCache() { return new PosixTimezoneCache(); }
TimezoneCache* OS::CreateTimezoneCache() {
return new PosixDefaultTimezoneCache();
}
void* OS::Allocate(const size_t requested, size_t* allocated,
OS::MemoryPermission access) {
......
......@@ -36,10 +36,10 @@
#undef MAP_TYPE
#include "src/base/macros.h"
#include "src/base/platform/platform-posix-time.h"
#include "src/base/platform/platform-posix.h"
#include "src/base/platform/platform.h"
namespace v8 {
namespace base {
......@@ -97,7 +97,9 @@ std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() {
void OS::SignalCodeMovingGC() {
}
TimezoneCache* OS::CreateTimezoneCache() { return new PosixTimezoneCache(); }
TimezoneCache* OS::CreateTimezoneCache() {
return new PosixDefaultTimezoneCache();
}
VirtualMemory::VirtualMemory() : address_(NULL), size_(0) { }
......
......@@ -27,13 +27,16 @@
#undef MAP_TYPE
#include "src/base/macros.h"
#include "src/base/platform/platform-posix-time.h"
#include "src/base/platform/platform-posix.h"
#include "src/base/platform/platform.h"
namespace v8 {
namespace base {
TimezoneCache* OS::CreateTimezoneCache() { return new PosixTimezoneCache(); }
TimezoneCache* OS::CreateTimezoneCache() {
return new PosixDefaultTimezoneCache();
}
void* OS::Allocate(const size_t requested, size_t* allocated,
OS::MemoryPermission access) {
......
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <cmath>
#include "src/base/platform/platform-posix-time.h"
namespace v8 {
namespace base {
const char* PosixDefaultTimezoneCache::LocalTimezone(double time) {
if (std::isnan(time)) return "";
time_t tv = static_cast<time_t>(std::floor(time / msPerSecond));
struct tm tm;
struct tm* t = localtime_r(&tv, &tm);
if (!t || !t->tm_zone) return "";
return t->tm_zone;
}
double PosixDefaultTimezoneCache::LocalTimeOffset() {
time_t tv = time(NULL);
struct tm tm;
struct tm* t = localtime_r(&tv, &tm);
// 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));
}
} // namespace base
} // namespace v8
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/base/platform/platform-posix.h"
namespace v8 {
namespace base {
class PosixDefaultTimezoneCache : public PosixTimezoneCache {
public:
const char* LocalTimezone(double time_ms) override;
double LocalTimeOffset() override;
~PosixDefaultTimezoneCache() override {}
};
} // namespace base
} // namespace v8
......@@ -390,26 +390,6 @@ double OS::TimeCurrentMillis() {
return Time::Now().ToJsTime();
}
#if !V8_OS_AIX && !V8_OS_SOLARIS && !V8_OS_CYGWIN
const char* PosixTimezoneCache::LocalTimezone(double time) {
if (std::isnan(time)) return "";
time_t tv = static_cast<time_t>(std::floor(time / msPerSecond));
struct tm tm;
struct tm* t = localtime_r(&tv, &tm);
if (!t || !t->tm_zone) return "";
return t->tm_zone;
}
double PosixTimezoneCache::LocalTimeOffset() {
time_t tv = time(NULL);
struct tm tm;
struct tm* t = localtime_r(&tv, &tm);
// 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
double PosixTimezoneCache::DaylightSavingsOffset(double time) {
if (std::isnan(time)) return std::numeric_limits<double>::quiet_NaN();
time_t tv = static_cast<time_t>(std::floor(time/msPerSecond));
......
......@@ -13,9 +13,7 @@ namespace base {
class PosixTimezoneCache : public TimezoneCache {
public:
const char* LocalTimezone(double time_ms) override;
double DaylightSavingsOffset(double time_ms) override;
double LocalTimeOffset() override;
void Clear() override {}
~PosixTimezoneCache() override {}
......
......@@ -31,6 +31,7 @@
#undef MAP_TYPE
#include "src/base/macros.h"
#include "src/base/platform/platform-posix-time.h"
#include "src/base/platform/platform-posix.h"
#include "src/base/platform/platform.h"
......@@ -84,7 +85,9 @@ bool OS::ArmUsingHardFloat() {
#endif // __arm__
TimezoneCache* OS::CreateTimezoneCache() { return new PosixTimezoneCache(); }
TimezoneCache* OS::CreateTimezoneCache() {
return new PosixDefaultTimezoneCache();
}
void* OS::Allocate(const size_t requested, size_t* allocated,
OS::MemoryPermission access) {
......
......@@ -1970,6 +1970,8 @@
'base/platform/platform-linux.cc',
'base/platform/platform-posix.h',
'base/platform/platform-posix.cc',
'base/platform/platform-posix-time.h',
'base/platform/platform-posix-time.cc',
],
}
],
......@@ -1978,6 +1980,8 @@
'base/debug/stack_trace_android.cc',
'base/platform/platform-posix.h',
'base/platform/platform-posix.cc',
'base/platform/platform-posix-time.h',
'base/platform/platform-posix-time.cc',
],
'link_settings': {
'target_conditions': [
......@@ -2034,6 +2038,8 @@
'base/debug/stack_trace_posix.cc',
'base/platform/platform-posix.h',
'base/platform/platform-posix.cc',
'base/platform/platform-posix-time.h',
'base/platform/platform-posix-time.cc',
'base/qnx-math.h'
],
'target_conditions': [
......@@ -2065,6 +2071,8 @@
'base/platform/platform-freebsd.cc',
'base/platform/platform-posix.h',
'base/platform/platform-posix.cc',
'base/platform/platform-posix-time.h',
'base/platform/platform-posix-time.cc',
],
}
],
......@@ -2077,6 +2085,8 @@
'base/platform/platform-openbsd.cc',
'base/platform/platform-posix.h',
'base/platform/platform-posix.cc'
'base/platform/platform-posix-time.h',
'base/platform/platform-posix-time.cc',
],
}
],
......@@ -2090,6 +2100,8 @@
'base/platform/platform-openbsd.cc',
'base/platform/platform-posix.h',
'base/platform/platform-posix.cc',
'base/platform/platform-posix-time.h',
'base/platform/platform-posix-time.cc',
],
}
],
......@@ -2126,6 +2138,8 @@
'base/platform/platform-macos.cc',
'base/platform/platform-posix.h',
'base/platform/platform-posix.cc',
'base/platform/platform-posix-time.h',
'base/platform/platform-posix-time.cc',
]},
],
['OS=="win"', {
......
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