Line data Source code
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 :
12 0 : const char* PosixDefaultTimezoneCache::LocalTimezone(double time) {
13 0 : if (std::isnan(time)) return "";
14 0 : time_t tv = static_cast<time_t>(std::floor(time / msPerSecond));
15 : struct tm tm;
16 0 : struct tm* t = localtime_r(&tv, &tm);
17 0 : if (!t || !t->tm_zone) return "";
18 0 : return t->tm_zone;
19 : }
20 :
21 10 : double 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 10 : time_t tv = time(nullptr);
25 : struct tm tm;
26 10 : struct tm* t = localtime_r(&tv, &tm);
27 : // tm_gmtoff includes any daylight savings offset, so subtract it.
28 20 : return static_cast<double>(t->tm_gmtoff * msPerSecond -
29 20 : (t->tm_isdst > 0 ? 3600 * msPerSecond : 0));
30 : }
31 :
32 : } // namespace base
33 : } // namespace v8
|