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