mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-13 11:25:02 -05:00
Remove unused GetTimeSeconds
This commit is contained in:
parent
27d7b11e8c
commit
fab9e8a29c
5 changed files with 21 additions and 20 deletions
|
@ -9,23 +9,26 @@
|
||||||
|
|
||||||
#include <chainparamsbase.h>
|
#include <chainparamsbase.h>
|
||||||
#include <clientversion.h>
|
#include <clientversion.h>
|
||||||
|
#include <compat/stdin.h>
|
||||||
#include <policy/feerate.h>
|
#include <policy/feerate.h>
|
||||||
#include <rpc/client.h>
|
#include <rpc/client.h>
|
||||||
#include <rpc/mining.h>
|
#include <rpc/mining.h>
|
||||||
#include <rpc/protocol.h>
|
#include <rpc/protocol.h>
|
||||||
#include <rpc/request.h>
|
#include <rpc/request.h>
|
||||||
#include <tinyformat.h>
|
#include <tinyformat.h>
|
||||||
|
#include <univalue.h>
|
||||||
#include <util/strencodings.h>
|
#include <util/strencodings.h>
|
||||||
#include <util/system.h>
|
#include <util/system.h>
|
||||||
#include <util/translation.h>
|
#include <util/translation.h>
|
||||||
#include <util/url.h>
|
#include <util/url.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <chrono>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <cstdio>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <stdio.h>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
|
||||||
|
@ -37,8 +40,11 @@
|
||||||
#include <event2/keyvalq_struct.h>
|
#include <event2/keyvalq_struct.h>
|
||||||
#include <support/events.h>
|
#include <support/events.h>
|
||||||
|
|
||||||
#include <univalue.h>
|
// The server returns time values from a mockable system clock, but it is not
|
||||||
#include <compat/stdin.h>
|
// trivial to get the mocked time from the server, nor is it needed for now, so
|
||||||
|
// just use a plain system_clock.
|
||||||
|
using CliClock = std::chrono::system_clock;
|
||||||
|
using CliSeconds = std::chrono::time_point<CliClock, std::chrono::seconds>;
|
||||||
|
|
||||||
const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;
|
const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;
|
||||||
UrlDecodeFn* const URL_DECODE = urlDecode;
|
UrlDecodeFn* const URL_DECODE = urlDecode;
|
||||||
|
@ -433,7 +439,7 @@ private:
|
||||||
if (conn_type == "addr-fetch") return "addr";
|
if (conn_type == "addr-fetch") return "addr";
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
const int64_t m_time_now{GetTimeSeconds()};
|
const int64_t m_time_now{count_seconds(Now<CliSeconds>())};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static constexpr int ID_PEERINFO = 0;
|
static constexpr int ID_PEERINFO = 0;
|
||||||
|
|
|
@ -194,7 +194,7 @@ int main(int argc, char** argv)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
std::signal(SIGABRT, signal_handler);
|
std::signal(SIGABRT, signal_handler);
|
||||||
int64_t start_time = GetTimeSeconds();
|
const auto start_time{Now<SteadySeconds>()};
|
||||||
int tested = 0;
|
int tested = 0;
|
||||||
for (int i = 1; i < argc; ++i) {
|
for (int i = 1; i < argc; ++i) {
|
||||||
fs::path input_path(*(argv + i));
|
fs::path input_path(*(argv + i));
|
||||||
|
@ -215,8 +215,8 @@ int main(int argc, char** argv)
|
||||||
buffer.clear();
|
buffer.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int64_t end_time = GetTimeSeconds();
|
const auto end_time{Now<SteadySeconds>()};
|
||||||
std::cout << g_fuzz_target << ": succeeded against " << tested << " files in " << (end_time - start_time) << "s." << std::endl;
|
std::cout << g_fuzz_target << ": succeeded against " << tested << " files in " << count_seconds(end_time - start_time) << "s." << std::endl;
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -265,9 +265,6 @@ BOOST_AUTO_TEST_CASE(util_FormatParseISO8601DateTime)
|
||||||
BOOST_CHECK_EQUAL(ParseISO8601DateTime("1970-01-01T00:00:00Z"), 0);
|
BOOST_CHECK_EQUAL(ParseISO8601DateTime("1970-01-01T00:00:00Z"), 0);
|
||||||
BOOST_CHECK_EQUAL(ParseISO8601DateTime("1960-01-01T00:00:00Z"), 0);
|
BOOST_CHECK_EQUAL(ParseISO8601DateTime("1960-01-01T00:00:00Z"), 0);
|
||||||
BOOST_CHECK_EQUAL(ParseISO8601DateTime("2011-09-30T23:36:17Z"), 1317425777);
|
BOOST_CHECK_EQUAL(ParseISO8601DateTime("2011-09-30T23:36:17Z"), 1317425777);
|
||||||
|
|
||||||
auto time = GetTimeSeconds();
|
|
||||||
BOOST_CHECK_EQUAL(ParseISO8601DateTime(FormatISO8601DateTime(time)), time);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(util_FormatISO8601Date)
|
BOOST_AUTO_TEST_CASE(util_FormatISO8601Date)
|
||||||
|
|
|
@ -115,11 +115,6 @@ int64_t GetTimeMicros()
|
||||||
return int64_t{GetSystemTime<std::chrono::microseconds>().count()};
|
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(); }
|
int64_t GetTime() { return GetTime<std::chrono::seconds>().count(); }
|
||||||
|
|
||||||
std::string FormatISO8601DateTime(int64_t nTime) {
|
std::string FormatISO8601DateTime(int64_t nTime) {
|
||||||
|
|
|
@ -21,15 +21,20 @@ using SteadyMicroseconds = std::chrono::time_point<std::chrono::steady_clock, st
|
||||||
void UninterruptibleSleep(const std::chrono::microseconds& n);
|
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
|
* 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.
|
* 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)
|
* 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_seconds(std::chrono::seconds t) { return t.count(); }
|
||||||
constexpr int64_t count_milliseconds(std::chrono::milliseconds 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(); }
|
constexpr int64_t count_microseconds(std::chrono::microseconds t) { return t.count(); }
|
||||||
|
@ -51,8 +56,6 @@ int64_t GetTime();
|
||||||
int64_t GetTimeMillis();
|
int64_t GetTimeMillis();
|
||||||
/** Returns the system time (not mockable) */
|
/** Returns the system time (not mockable) */
|
||||||
int64_t GetTimeMicros();
|
int64_t GetTimeMicros();
|
||||||
/** Returns the system time (not mockable) */
|
|
||||||
int64_t GetTimeSeconds(); // Like GetTime(), but not mockable
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DEPRECATED
|
* DEPRECATED
|
||||||
|
|
Loading…
Add table
Reference in a new issue