|
3 | 3 | // Distributed under the MIT software license, see the accompanying |
4 | 4 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. |
5 | 5 |
|
6 | | -#if defined(HAVE_CONFIG_H) |
7 | | -#include <config/bitcoin-config.h> |
8 | | -#endif |
| 6 | +#include <util/time.h> |
9 | 7 |
|
10 | 8 | #include <compat/compat.h> |
11 | 9 | #include <tinyformat.h> |
12 | | -#include <util/time.h> |
13 | 10 | #include <util/check.h> |
14 | 11 |
|
15 | 12 | #include <atomic> |
16 | 13 | #include <chrono> |
17 | | -#include <ctime> |
18 | | -#include <locale> |
19 | | -#include <thread> |
20 | | -#include <sstream> |
21 | 14 | #include <string> |
| 15 | +#include <thread> |
22 | 16 |
|
23 | 17 | void UninterruptibleSleep(const std::chrono::microseconds& n) { std::this_thread::sleep_for(n); } |
24 | 18 |
|
@@ -53,30 +47,21 @@ std::chrono::seconds GetMockTime() |
53 | 47 |
|
54 | 48 | int64_t GetTime() { return GetTime<std::chrono::seconds>().count(); } |
55 | 49 |
|
56 | | -std::string FormatISO8601DateTime(int64_t nTime) { |
57 | | - struct tm ts; |
58 | | - time_t time_val = nTime; |
59 | | -#ifdef HAVE_GMTIME_R |
60 | | - if (gmtime_r(&time_val, &ts) == nullptr) { |
61 | | -#else |
62 | | - if (gmtime_s(&ts, &time_val) != 0) { |
63 | | -#endif |
64 | | - return {}; |
65 | | - } |
66 | | - return strprintf("%04i-%02i-%02iT%02i:%02i:%02iZ", ts.tm_year + 1900, ts.tm_mon + 1, ts.tm_mday, ts.tm_hour, ts.tm_min, ts.tm_sec); |
| 50 | +std::string FormatISO8601DateTime(int64_t nTime) |
| 51 | +{ |
| 52 | + const std::chrono::sys_seconds secs{std::chrono::seconds{nTime}}; |
| 53 | + const auto days{std::chrono::floor<std::chrono::days>(secs)}; |
| 54 | + const std::chrono::year_month_day ymd{days}; |
| 55 | + const std::chrono::hh_mm_ss hms{secs - days}; |
| 56 | + return strprintf("%04i-%02u-%02uT%02i:%02i:%02iZ", signed{ymd.year()}, unsigned{ymd.month()}, unsigned{ymd.day()}, hms.hours().count(), hms.minutes().count(), hms.seconds().count()); |
67 | 57 | } |
68 | 58 |
|
69 | | -std::string FormatISO8601Date(int64_t nTime) { |
70 | | - struct tm ts; |
71 | | - time_t time_val = nTime; |
72 | | -#ifdef HAVE_GMTIME_R |
73 | | - if (gmtime_r(&time_val, &ts) == nullptr) { |
74 | | -#else |
75 | | - if (gmtime_s(&ts, &time_val) != 0) { |
76 | | -#endif |
77 | | - return {}; |
78 | | - } |
79 | | - return strprintf("%04i-%02i-%02i", ts.tm_year + 1900, ts.tm_mon + 1, ts.tm_mday); |
| 59 | +std::string FormatISO8601Date(int64_t nTime) |
| 60 | +{ |
| 61 | + const std::chrono::sys_seconds secs{std::chrono::seconds{nTime}}; |
| 62 | + const auto days{std::chrono::floor<std::chrono::days>(secs)}; |
| 63 | + const std::chrono::year_month_day ymd{days}; |
| 64 | + return strprintf("%04i-%02u-%02u", signed{ymd.year()}, unsigned{ymd.month()}, unsigned{ymd.day()}); |
80 | 65 | } |
81 | 66 |
|
82 | 67 | struct timeval MillisToTimeval(int64_t nTimeout) |
|
0 commit comments