Bitcoin Core 30.99.0
P2P Digital Currency
Functions | Variables
time.cpp File Reference
#include <util/time.h>
#include <compat/compat.h>
#include <tinyformat.h>
#include <util/check.h>
#include <util/strencodings.h>
#include <array>
#include <atomic>
#include <chrono>
#include <optional>
#include <string>
#include <string_view>
#include <thread>
Include dependency graph for time.cpp:

Go to the source code of this file.

Functions

void UninterruptibleSleep (const std::chrono::microseconds &n)
 
void SetMockTime (int64_t nMockTimeIn)
 DEPRECATED Use SetMockTime with chrono type. More...
 
void SetMockTime (std::chrono::time_point< NodeClock, std::chrono::seconds > mock)
 
void SetMockTime (std::chrono::seconds mock_time_in)
 For testing. More...
 
std::chrono::seconds GetMockTime ()
 For testing. More...
 
int64_t GetTime ()
 DEPRECATED Use either ClockType::now() or Now<TimePointType>() if a cast is needed. More...
 
std::string FormatISO8601DateTime (int64_t nTime)
 ISO 8601 formatting is preferred. More...
 
std::string FormatISO8601Date (int64_t nTime)
 
std::optional< int64_t > ParseISO8601DateTime (std::string_view str)
 
std::string FormatRFC1123DateTime (int64_t time)
 RFC1123 formatting https://www.rfc-editor.org/rfc/rfc1123#section-5.2.14 Used in HTTP/1.1 responses. More...
 
struct timeval MillisToTimeval (int64_t nTimeout)
 Convert milliseconds to a struct timeval for e.g. More...
 
struct timeval MillisToTimeval (std::chrono::milliseconds ms)
 Convert milliseconds to a struct timeval for e.g. More...
 

Variables

static constexpr std::array< std::string_view, 7 > weekdays {"Thu", "Fri", "Sat", "Sun", "Mon", "Tue", "Wed"}
 
static constexpr std::array< std::string_view, 12 > months {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}
 
static std::atomic< std::chrono::seconds > g_mock_time {}
 For testing. More...
 
std::atomic< bool > g_used_system_time {false}
 
static std::atomic< MockableSteadyClock::mock_time_point::duration > g_mock_steady_time {}
 For testing. More...
 

Function Documentation

◆ FormatISO8601Date()

std::string FormatISO8601Date ( int64_t  nTime)

Definition at line 92 of file time.cpp.

Here is the caller graph for this function:

◆ FormatISO8601DateTime()

std::string FormatISO8601DateTime ( int64_t  nTime)

ISO 8601 formatting is preferred.

Use the FormatISO8601{DateTime,Date} helper functions if possible.

Definition at line 83 of file time.cpp.

Here is the caller graph for this function:

◆ FormatRFC1123DateTime()

std::string FormatRFC1123DateTime ( int64_t  time)

RFC1123 formatting https://www.rfc-editor.org/rfc/rfc1123#section-5.2.14 Used in HTTP/1.1 responses.

Definition at line 124 of file time.cpp.

Here is the caller graph for this function:

◆ GetMockTime()

std::chrono::seconds GetMockTime ( )

For testing.

Definition at line 52 of file time.cpp.

Here is the caller graph for this function:

◆ GetTime()

int64_t GetTime ( )

DEPRECATED Use either ClockType::now() or Now<TimePointType>() if a cast is needed.

ClockType is

  • SteadyClock/std::chrono::steady_clock for steady time
  • SystemClock/std::chrono::system_clock for system time
  • NodeClock for mockable system time

Definition at line 81 of file time.cpp.

Here is the caller graph for this function:

◆ MillisToTimeval() [1/2]

struct timeval MillisToTimeval ( int64_t  nTimeout)

Convert milliseconds to a struct timeval for e.g.

select.

Definition at line 142 of file time.cpp.

Here is the caller graph for this function:

◆ MillisToTimeval() [2/2]

struct timeval MillisToTimeval ( std::chrono::milliseconds  ms)

Convert milliseconds to a struct timeval for e.g.

select.

Definition at line 150 of file time.cpp.

Here is the call graph for this function:

◆ ParseISO8601DateTime()

std::optional< int64_t > ParseISO8601DateTime ( std::string_view  str)

Definition at line 100 of file time.cpp.

Here is the caller graph for this function:

◆ SetMockTime() [1/3]

void SetMockTime ( int64_t  nMockTimeIn)

DEPRECATED Use SetMockTime with chrono type.

Parameters
[in]nMockTimeInTime in seconds.

Definition at line 44 of file time.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetMockTime() [2/3]

void SetMockTime ( std::chrono::seconds  mock_time_in)

For testing.

Set e.g. with the setmocktime rpc, or -mocktime argument

Definition at line 46 of file time.cpp.

◆ SetMockTime() [3/3]

void SetMockTime ( std::chrono::time_point< NodeClock, std::chrono::seconds >  mock)

Definition at line 45 of file time.cpp.

Here is the call graph for this function:

◆ UninterruptibleSleep()

void UninterruptibleSleep ( const std::chrono::microseconds &  n)

Definition at line 24 of file time.cpp.

Here is the caller graph for this function:

Variable Documentation

◆ g_mock_steady_time

std::atomic<MockableSteadyClock::mock_time_point::duration> g_mock_steady_time {}
static

For testing.

Definition at line 28 of file time.cpp.

◆ g_mock_time

std::atomic<std::chrono::seconds> g_mock_time {}
static

For testing.

Definition at line 26 of file time.cpp.

◆ g_used_system_time

std::atomic<bool> g_used_system_time {false}

Definition at line 27 of file time.cpp.

◆ months

constexpr std::array<std::string_view, 12> months {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}
staticconstexpr

Definition at line 22 of file time.cpp.

◆ weekdays

constexpr std::array<std::string_view, 7> weekdays {"Thu", "Fri", "Sat", "Sun", "Mon", "Tue", "Wed"}
staticconstexpr

Definition at line 21 of file time.cpp.