diff options
author | MacroFake <falke.marco@gmail.com> | 2022-05-12 10:04:18 +0200 |
---|---|---|
committer | MacroFake <falke.marco@gmail.com> | 2022-05-12 10:04:54 +0200 |
commit | dd9f61a184d4d395591ee3e9f1e839473e88ffd0 (patch) | |
tree | 9b95e2730f4468a3be0850218fd4ce217ad433b0 /src/util | |
parent | e3bab43329e78e93e13b8f55330b183c3a3c954e (diff) | |
parent | fab9e8a29c2cdeab6cf1ae7c1fc0e0a3af783b17 (diff) |
Merge bitcoin/bitcoin#25102: Remove unused GetTimeSeconds
fab9e8a29c2cdeab6cf1ae7c1fc0e0a3af783b17 Remove unused GetTimeSeconds (MacroFake)
Pull request description:
Seems confusing to have this helper when it is possible to get the system time in a type-safe way by simply calling `std::chrono::system_clock::now` (C++11).
This patch replaces `GetTimeSeconds` and removes it:
* in `bitcoin-cli.cpp` by `system_clock`
* in `test/fuzz/fuzz.cpp` by `steady_clock`
ACKs for top commit:
laanwj:
Code review ACK fab9e8a29c2cdeab6cf1ae7c1fc0e0a3af783b17
naumenkogs:
ACK fab9e8a29c2cdeab6cf1ae7c1fc0e0a3af783b17
Tree-SHA512: 517e300b0baf271cfbeebd4a0838871acbea9360f9dd23572a751335c20c1ba261b1b5ee0aec8a36abd20c94fab83ce94f46042745279aca1f0ca2f885a03b6e
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/time.cpp | 5 | ||||
-rw-r--r-- | src/util/time.h | 13 |
2 files changed, 8 insertions, 10 deletions
diff --git a/src/util/time.cpp b/src/util/time.cpp index e428430bac..4ec44509ab 100644 --- a/src/util/time.cpp +++ b/src/util/time.cpp @@ -115,11 +115,6 @@ int64_t GetTimeMicros() return int64_t{GetSystemTime<std::chrono::microseconds>().count()}; } -int64_t GetTimeSeconds() -{ - return int64_t{GetSystemTime<std::chrono::seconds>().count()}; -} - int64_t GetTime() { return GetTime<std::chrono::seconds>().count(); } std::string FormatISO8601DateTime(int64_t nTime) { diff --git a/src/util/time.h b/src/util/time.h index 041b8aa6a1..72956ea0d7 100644 --- a/src/util/time.h +++ b/src/util/time.h @@ -21,15 +21,20 @@ using SteadyMicroseconds = std::chrono::time_point<std::chrono::steady_clock, st void UninterruptibleSleep(const std::chrono::microseconds& n); /** - * Helper to count the seconds of a duration. + * Helper to count the seconds of a duration/time_point. * - * All durations should be using std::chrono and calling this should generally + * All durations/time_points should be using std::chrono and calling this should generally * be avoided in code. Though, it is still preferred to an inline t.count() to * protect against a reliance on the exact type of t. * - * This helper is used to convert durations before passing them over an + * This helper is used to convert durations/time_points before passing them over an * interface that doesn't support std::chrono (e.g. RPC, debug log, or the GUI) */ +template <typename Clock> +constexpr int64_t count_seconds(std::chrono::time_point<Clock, std::chrono::seconds> t) +{ + return t.time_since_epoch().count(); +} constexpr int64_t count_seconds(std::chrono::seconds t) { return t.count(); } constexpr int64_t count_milliseconds(std::chrono::milliseconds t) { return t.count(); } constexpr int64_t count_microseconds(std::chrono::microseconds t) { return t.count(); } @@ -51,8 +56,6 @@ int64_t GetTime(); int64_t GetTimeMillis(); /** Returns the system time (not mockable) */ int64_t GetTimeMicros(); -/** Returns the system time (not mockable) */ -int64_t GetTimeSeconds(); // Like GetTime(), but not mockable /** * DEPRECATED |