-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deps: cherry-pick fa4ec9f from V8 upstream
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: #14608 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com>
- Loading branch information
1 parent
1a2f749
commit bfb97b7
Showing
12 changed files
with
88 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters