Bitcoin ABC  0.26.2
P2P Digital Currency
time.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2019 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 <compat.h>
10 
11 #include <chrono>
12 #include <cstdint>
13 #include <string>
14 
15 using namespace std::chrono_literals;
16 
17 void UninterruptibleSleep(const std::chrono::microseconds &n);
18 
29 constexpr int64_t count_seconds(std::chrono::seconds t) {
30  return t.count();
31 }
32 constexpr int64_t count_milliseconds(std::chrono::milliseconds t) {
33  return t.count();
34 }
35 constexpr int64_t count_microseconds(std::chrono::microseconds t) {
36  return t.count();
37 }
38 
40  std::chrono::duration<double, std::chrono::seconds::period>;
41 
46  return t.count();
47 }
48 
53 int64_t GetTime();
54 
56 int64_t GetTimeMillis();
58 int64_t GetTimeMicros();
60 // Like GetTime(), but not mockable
61 int64_t GetTimeSeconds();
62 
64 void SetMockTime(int64_t nMockTimeIn);
66 int64_t GetMockTime();
67 
69 template <typename T> T GetTime();
70 
75 std::string FormatISO8601DateTime(int64_t nTime);
76 std::string FormatISO8601Date(int64_t nTime);
77 int64_t ParseISO8601DateTime(const std::string &str);
78 
82 struct timeval MillisToTimeval(int64_t nTimeout);
83 
87 struct timeval MillisToTimeval(std::chrono::milliseconds ms);
88 
90 bool ChronoSanityCheck();
91 
92 #endif // BITCOIN_UTIL_TIME_H
constexpr int64_t count_milliseconds(std::chrono::milliseconds t)
Definition: time.h:32
struct timeval MillisToTimeval(int64_t nTimeout)
Convert milliseconds to a struct timeval for e.g.
Definition: time.cpp:164
int64_t GetTimeMicros()
Returns the system time (not mockable)
Definition: time.cpp:107
int64_t GetTimeMillis()
Returns the system time (not mockable)
Definition: time.cpp:103
std::chrono::duration< double, std::chrono::seconds::period > SecondsDouble
Definition: time.h:40
void UninterruptibleSleep(const std::chrono::microseconds &n)
Definition: time.cpp:23
int64_t GetTime()
DEPRECATED Use either GetTimeSeconds (not mockable) or GetTime<T> (mockable)
Definition: time.cpp:71
int64_t GetTimeSeconds()
Returns the system time (not mockable)
Definition: time.cpp:111
std::string FormatISO8601Date(int64_t nTime)
Definition: time.cpp:134
void SetMockTime(int64_t nMockTimeIn)
For testing.
Definition: time.cpp:94
constexpr int64_t count_microseconds(std::chrono::microseconds t)
Definition: time.h:35
constexpr int64_t count_seconds(std::chrono::seconds t)
Helper to count the seconds of a duration.
Definition: time.h:29
int64_t ParseISO8601DateTime(const std::string &str)
Definition: time.cpp:148
double CountSecondsDouble(SecondsDouble t)
Helper to count the seconds in any std::chrono::duration type.
Definition: time.h:45
int64_t GetMockTime()
For testing.
Definition: time.cpp:99
bool ChronoSanityCheck()
Sanity check epoch match normal Unix epoch.
Definition: time.cpp:30
std::string FormatISO8601DateTime(int64_t nTime)
ISO 8601 formatting is preferred.
Definition: time.cpp:119