Index: src/base/platform/platform-win32.cc |
diff --git a/src/base/platform/platform-win32.cc b/src/base/platform/platform-win32.cc |
index 60b60fdcd298723fa7e8adfdec69e54300ad1402..33064dafa46e0a3c821eb7f5cc59c4961eebd180 100644 |
--- a/src/base/platform/platform-win32.cc |
+++ b/src/base/platform/platform-win32.cc |
@@ -24,9 +24,9 @@ |
#include "src/base/macros.h" |
#include "src/base/platform/platform.h" |
#include "src/base/platform/time.h" |
+#include "src/base/timezone-cache.h" |
#include "src/base/utils/random-number-generator.h" |
- |
// Extra functions for MinGW. Most of these are the _s functions which are in |
// the Microsoft Visual Studio C++ CRT. |
#ifdef __MINGW32__ |
@@ -101,13 +101,19 @@ bool g_hard_abort = false; |
} // namespace |
-class TimezoneCache { |
+class WindowsTimezoneCache : public TimezoneCache { |
public: |
- TimezoneCache() : initialized_(false) { } |
+ WindowsTimezoneCache() : initialized_(false) {} |
- void Clear() { |
- initialized_ = false; |
- } |
+ ~WindowsTimezoneCache() override {} |
+ |
+ void Clear() override { initialized_ = false; } |
+ |
+ const char* LocalTimezone(double time) override; |
+ |
+ double LocalTimeOffset() override; |
+ |
+ double DaylightSavingsOffset(double time) override; |
// Initialize timezone information. The timezone information is obtained from |
// windows. If we cannot get the timezone information we fall back to CET. |
@@ -216,14 +222,14 @@ class Win32Time { |
// LocalOffset(CET) = 3600000 and LocalOffset(PST) = -28800000. This |
// routine also takes into account whether daylight saving is effect |
// at the time. |
- int64_t LocalOffset(TimezoneCache* cache); |
+ int64_t LocalOffset(WindowsTimezoneCache* cache); |
// Returns the daylight savings time offset for the time in milliseconds. |
- int64_t DaylightSavingsOffset(TimezoneCache* cache); |
+ int64_t DaylightSavingsOffset(WindowsTimezoneCache* cache); |
// Returns a string identifying the current timezone for the |
// timestamp taking into account daylight saving. |
- char* LocalTimezone(TimezoneCache* cache); |
+ char* LocalTimezone(WindowsTimezoneCache* cache); |
private: |
// Constants for time conversion. |
@@ -235,7 +241,7 @@ class Win32Time { |
static const bool kShortTzNames = false; |
// Return whether or not daylight savings time is in effect at this time. |
- bool InDST(TimezoneCache* cache); |
+ bool InDST(WindowsTimezoneCache* cache); |
// Accessor for FILETIME representation. |
FILETIME& ft() { return time_.ft_; } |
@@ -350,7 +356,7 @@ void Win32Time::SetToCurrentTime() { |
// Only times in the 32-bit Unix range may be passed to this function. |
// Also, adding the time-zone offset to the input must not overflow. |
// The function EquivalentTime() in date.js guarantees this. |
-int64_t Win32Time::LocalOffset(TimezoneCache* cache) { |
+int64_t Win32Time::LocalOffset(WindowsTimezoneCache* cache) { |
cache->InitializeIfNeeded(); |
Win32Time rounded_to_second(*this); |
@@ -384,7 +390,7 @@ int64_t Win32Time::LocalOffset(TimezoneCache* cache) { |
// Return whether or not daylight savings time is in effect at this time. |
-bool Win32Time::InDST(TimezoneCache* cache) { |
+bool Win32Time::InDST(WindowsTimezoneCache* cache) { |
cache->InitializeIfNeeded(); |
// Determine if DST is in effect at the specified time. |
@@ -409,14 +415,14 @@ bool Win32Time::InDST(TimezoneCache* cache) { |
// Return the daylight savings time offset for this time. |
-int64_t Win32Time::DaylightSavingsOffset(TimezoneCache* cache) { |
+int64_t Win32Time::DaylightSavingsOffset(WindowsTimezoneCache* cache) { |
return InDST(cache) ? 60 * kMsPerMinute : 0; |
} |
// Returns a string identifying the current timezone for the |
// timestamp taking into account daylight saving. |
-char* Win32Time::LocalTimezone(TimezoneCache* cache) { |
+char* Win32Time::LocalTimezone(WindowsTimezoneCache* cache) { |
// Return the standard or DST time zone name based on whether daylight |
// saving is in effect at the given time. |
return InDST(cache) ? cache->dst_tz_name_ : cache->std_tz_name_; |
@@ -448,47 +454,30 @@ double OS::TimeCurrentMillis() { |
return Time::Now().ToJsTime(); |
} |
- |
-TimezoneCache* OS::CreateTimezoneCache() { |
- return new TimezoneCache(); |
-} |
- |
- |
-void OS::DisposeTimezoneCache(TimezoneCache* cache) { |
- delete cache; |
-} |
- |
- |
-void OS::ClearTimezoneCache(TimezoneCache* cache) { |
- cache->Clear(); |
-} |
- |
- |
// Returns a string identifying the current timezone taking into |
// account daylight saving. |
-const char* OS::LocalTimezone(double time, TimezoneCache* cache) { |
- return Win32Time(time).LocalTimezone(cache); |
+const char* WindowsTimezoneCache::LocalTimezone(double time) { |
+ return Win32Time(time).LocalTimezone(this); |
} |
- |
// Returns the local time offset in milliseconds east of UTC without |
// taking daylight savings time into account. |
-double OS::LocalTimeOffset(TimezoneCache* cache) { |
+double WindowsTimezoneCache::LocalTimeOffset() { |
// Use current time, rounded to the millisecond. |
- Win32Time t(TimeCurrentMillis()); |
+ Win32Time t(OS::TimeCurrentMillis()); |
// Time::LocalOffset inlcudes any daylight savings offset, so subtract it. |
- return static_cast<double>(t.LocalOffset(cache) - |
- t.DaylightSavingsOffset(cache)); |
+ return static_cast<double>(t.LocalOffset(this) - |
+ t.DaylightSavingsOffset(this)); |
} |
- |
// Returns the daylight savings offset in milliseconds for the given |
// time. |
-double OS::DaylightSavingsOffset(double time, TimezoneCache* cache) { |
- int64_t offset = Win32Time(time).DaylightSavingsOffset(cache); |
+double WindowsTimezoneCache::DaylightSavingsOffset(double time) { |
+ int64_t offset = Win32Time(time).DaylightSavingsOffset(this); |
return static_cast<double>(offset); |
} |
+TimezoneCache* OS::CreateTimezoneCache() { return new WindowsTimezoneCache(); } |
int OS::GetLastError() { |
return ::GetLastError(); |