v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
platform-posix-time.cc
Go to the documentation of this file.
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
8
9namespace v8 {
10namespace base {
11
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
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);
28 // tm_gmtoff includes any daylight savings offset, so subtract it.
29 return static_cast<double>(t->tm_gmtoff * msPerSecond -
30 (t->tm_isdst > 0 ? 3600 * msPerSecond : 0));
31}
32
33} // namespace base
34} // namespace v8
const char * LocalTimezone(double time_ms) override
double LocalTimeOffset(double time_ms, bool is_utc) override
TimeRecord time
#define DCHECK_NOT_NULL(val)
Definition logging.h:492