1 // Copyright 2017 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include <cmath> 6 7 #include "src/base/platform/platform-posix-time.h" 8 9 namespace v8 { 10 namespace base { 11 LocalTimezone(double time)12const char* PosixDefaultTimezoneCache::LocalTimezone(double time) { 13 if (std::isnan(time)) return ""; 14 time_t tv = static_cast<time_t>(std::floor(time / msPerSecond)); 15 struct tm tm; 16 struct tm* t = localtime_r(&tv, &tm); 17 if (!t || !t->tm_zone) return ""; 18 return t->tm_zone; 19 } 20 LocalTimeOffset(double time_ms,bool is_utc)21double PosixDefaultTimezoneCache::LocalTimeOffset(double time_ms, bool is_utc) { 22 // Preserve the old behavior for non-ICU implementation by ignoring both 23 // time_ms and is_utc. 24 time_t tv = time(nullptr); 25 struct tm tm; 26 struct tm* t = localtime_r(&tv, &tm); 27 // tm_gmtoff includes any daylight savings offset, so subtract it. 28 return static_cast<double>(t->tm_gmtoff * msPerSecond - 29 (t->tm_isdst > 0 ? 3600 * msPerSecond : 0)); 30 } 31 32 } // namespace base 33 } // namespace v8 34