mirror of https://github.com/lukechilds/node.git
Browse Source
Original commit message: [date] Refactor PosixTimezoneCache for different OS Follow up on https://codereview.chromium.org/2740353002. Created PosixDefaultTimezoneCache which is a subclass of PosixTimezoneCache containing definition of LocalTimezone and LocalTimeOffset which is separate for different OS. R=littledan@chromium.org, ulan@chromium.org BUG=v8:6578 LOG=N Change-Id: I58342893aeefe79ac50e1df041d614fc473f15bf Reviewed-on: https://chromium-review.googlesource.com/568686 Reviewed-by: Daniel Ehrenberg <littledan@chromium.org> Commit-Queue: Jaideep Bajwa <bjaideep@ca.ibm.com> Cr-Commit-Position: refs/heads/master@{#46604} PR-URL: https://github.com/nodejs/node/pull/14608 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com>canary-base
committed by
Ben Noordhuis
12 changed files with 88 additions and 30 deletions
@ -0,0 +1,31 @@ |
|||||
|
// Copyright 2017 the V8 project authors. All rights reserved.
|
||||
|
// Use of this source code is governed by a BSD-style license that can be
|
||||
|
// found in the LICENSE file.
|
||||
|
|
||||
|
#include <cmath> |
||||
|
|
||||
|
#include "src/base/platform/platform-posix-time.h" |
||||
|
|
||||
|
namespace v8 { |
||||
|
namespace base { |
||||
|
|
||||
|
const char* PosixDefaultTimezoneCache::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; |
||||
|
} |
||||
|
|
||||
|
double PosixDefaultTimezoneCache::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)); |
||||
|
} |
||||
|
|
||||
|
} // namespace base
|
||||
|
} // namespace v8
|
@ -0,0 +1,19 @@ |
|||||
|
// Copyright 2017 the V8 project authors. All rights reserved.
|
||||
|
// Use of this source code is governed by a BSD-style license that can be
|
||||
|
// found in the LICENSE file.
|
||||
|
|
||||
|
#include "src/base/platform/platform-posix.h" |
||||
|
|
||||
|
namespace v8 { |
||||
|
namespace base { |
||||
|
|
||||
|
class PosixDefaultTimezoneCache : public PosixTimezoneCache { |
||||
|
public: |
||||
|
const char* LocalTimezone(double time_ms) override; |
||||
|
double LocalTimeOffset() override; |
||||
|
|
||||
|
~PosixDefaultTimezoneCache() override {} |
||||
|
}; |
||||
|
|
||||
|
} // namespace base
|
||||
|
} // namespace v8
|
Loading…
Reference in new issue