Bitcoin Core  0.20.99
P2P Digital Currency
time.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2020 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #ifndef BITCOIN_UTIL_TIME_H
7 #define BITCOIN_UTIL_TIME_H
8 
9 #include <stdint.h>
10 #include <string>
11 #include <chrono>
12 
13 void UninterruptibleSleep(const std::chrono::microseconds& n);
14 
25 inline int64_t count_seconds(std::chrono::seconds t) { return t.count(); }
26 inline int64_t count_microseconds(std::chrono::microseconds t) { return t.count(); }
27 
32 int64_t GetTime();
33 
35 int64_t GetTimeMillis();
37 int64_t GetTimeMicros();
39 int64_t GetSystemTimeInSeconds(); // Like GetTime(), but not mockable
40 
42 void SetMockTime(int64_t nMockTimeIn);
44 int64_t GetMockTime();
45 
47 template <typename T>
48 T GetTime();
49 
54 std::string FormatISO8601DateTime(int64_t nTime);
55 std::string FormatISO8601Date(int64_t nTime);
56 int64_t ParseISO8601DateTime(const std::string& str);
57 
58 #endif // BITCOIN_UTIL_TIME_H
int64_t count_microseconds(std::chrono::microseconds t)
Definition: time.h:26
int64_t GetSystemTimeInSeconds()
Returns the system time (not mockable)
Definition: time.cpp:73
void UninterruptibleSleep(const std::chrono::microseconds &n)
Definition: time.cpp:19
int64_t count_seconds(std::chrono::seconds t)
Helper to count the seconds of a duration.
Definition: time.h:25
int64_t GetTime()
DEPRECATED Use either GetSystemTimeInSeconds (not mockable) or GetTime<T> (mockable) ...
Definition: time.cpp:23
int64_t GetTimeMillis()
Returns the system time (not mockable)
Definition: time.cpp:57
int64_t GetMockTime()
For testing.
Definition: time.cpp:52
int64_t ParseISO8601DateTime(const std::string &str)
Definition: time.cpp:104
std::string FormatISO8601Date(int64_t nTime)
Definition: time.cpp:91
std::string FormatISO8601DateTime(int64_t nTime)
ISO 8601 formatting is preferred.
Definition: time.cpp:78
void SetMockTime(int64_t nMockTimeIn)
For testing.
Definition: time.cpp:47
int64_t GetTimeMicros()
Returns the system time (not mockable)
Definition: time.cpp:65