Index: src/base/platform/platform-posix.cc |
diff --git a/src/base/platform/platform-posix.cc b/src/base/platform/platform-posix.cc |
index f195649e5e9f818c7bfab97f67f3439abbf26061..3b8045a7675d7736f64f473629ddf14e99e04808 100644 |
--- a/src/base/platform/platform-posix.cc |
+++ b/src/base/platform/platform-posix.cc |
@@ -37,6 +37,8 @@ |
#include <cmath> |
#include <cstdlib> |
+#include "src/base/platform/platform-posix.h" |
+ |
#include "src/base/lazy-instance.h" |
#include "src/base/macros.h" |
#include "src/base/platform/platform.h" |
@@ -380,26 +382,25 @@ double OS::TimeCurrentMillis() { |
return Time::Now().ToJsTime(); |
} |
- |
-class TimezoneCache {}; |
- |
- |
-TimezoneCache* OS::CreateTimezoneCache() { |
- return NULL; |
-} |
- |
- |
-void OS::DisposeTimezoneCache(TimezoneCache* cache) { |
- DCHECK(cache == NULL); |
+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; |
} |
- |
-void OS::ClearTimezoneCache(TimezoneCache* cache) { |
- DCHECK(cache == NULL); |
+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)); |
} |
- |
-double OS::DaylightSavingsOffset(double time, TimezoneCache*) { |
+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)); |
struct tm tm; |