|
1 | 1 | // Copyright (c) 2009-2010 Satoshi Nakamoto |
2 | 2 | // Copyright (c) 2009-2014 The Bitcoin developers |
3 | | -// Copyright (c) 2016-2017 The PIVX developers |
| 3 | +// Copyright (c) 2016-2019 The PIVX developers |
4 | 4 | // Distributed under the MIT software license, see the accompanying |
5 | 5 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. |
6 | 6 |
|
|
9 | 9 |
|
10 | 10 | #include <stdint.h> |
11 | 11 | #include <string> |
| 12 | +#include <chrono> |
12 | 13 |
|
13 | 14 | /** |
14 | | - * GetTimeMicros() and GetTimeMillis() both return the system time, but in |
15 | | - * different units. GetTime() returns the sytem time in seconds, but also |
16 | | - * supports mocktime, where the time can be specified by the user, eg for |
17 | | - * testing (eg with the setmocktime rpc, or -mocktime argument). |
18 | | - * |
19 | | - * TODO: Rework these functions to be type-safe (so that we don't inadvertently |
20 | | - * compare numbers with different units, or compare a mocktime to system time). |
| 15 | + * DEPRECATED |
| 16 | + * Use either GetSystemTimeInSeconds (not mockable) or GetTime<T> (mockable) |
21 | 17 | */ |
22 | | - |
23 | 18 | int64_t GetTime(); |
| 19 | +/** Returns the system time (not mockable) */ |
24 | 20 | int64_t GetTimeMillis(); |
| 21 | +/** Returns the system time (not mockable) */ |
25 | 22 | int64_t GetTimeMicros(); |
| 23 | +/** Returns the system time (not mockable) */ |
26 | 24 | int64_t GetSystemTimeInSeconds(); // Like GetTime(), but not mockable |
| 25 | +/** For testing. Set e.g. with the setmocktime rpc, or -mocktime argument */ |
27 | 26 | void SetMockTime(int64_t nMockTimeIn); |
| 27 | +/** For testing */ |
28 | 28 | int64_t GetMockTime(); |
| 29 | + |
29 | 30 | void MilliSleep(int64_t n); |
30 | 31 |
|
31 | 32 | std::string DurationToDHMS(int64_t nDurationTime); |
32 | 33 |
|
| 34 | +/** Return system time (or mocked time, if set) */ |
| 35 | +template <typename T> |
| 36 | +T GetTime(); |
| 37 | + |
33 | 38 | /** |
34 | 39 | * ISO 8601 formatting is preferred. Use the FormatISO8601{DateTime,Date,Time} |
35 | 40 | * helper functions if possible. |
|
0 commit comments