Bitcoin Core 28.99.0
P2P Digital Currency
Classes | Typedefs | Functions
time.h File Reference
#include <chrono>
#include <cstdint>
#include <optional>
#include <string>
#include <string_view>
Include dependency graph for time.h:

Go to the source code of this file.

Classes

struct  NodeClock
 Mockable clock in the context of tests, otherwise the system clock. More...
 

Typedefs

using NodeSeconds = std::chrono::time_point< NodeClock, std::chrono::seconds >
 
using SteadyClock = std::chrono::steady_clock
 
using SteadySeconds = std::chrono::time_point< std::chrono::steady_clock, std::chrono::seconds >
 
using SteadyMilliseconds = std::chrono::time_point< std::chrono::steady_clock, std::chrono::milliseconds >
 
using SteadyMicroseconds = std::chrono::time_point< std::chrono::steady_clock, std::chrono::microseconds >
 
using SystemClock = std::chrono::system_clock
 
using HoursDouble = std::chrono::duration< double, std::chrono::hours::period >
 
using SecondsDouble = std::chrono::duration< double, std::chrono::seconds::period >
 
using MillisecondsDouble = std::chrono::duration< double, std::chrono::milliseconds::period >
 

Functions

void UninterruptibleSleep (const std::chrono::microseconds &n)
 
template<typename Dur1 , typename Dur2 >
constexpr auto Ticks (Dur2 d)
 Helper to count the seconds of a duration/time_point. More...
 
template<typename Duration , typename Timepoint >
constexpr auto TicksSinceEpoch (Timepoint t)
 
constexpr int64_t count_seconds (std::chrono::seconds t)
 
constexpr int64_t count_milliseconds (std::chrono::milliseconds t)
 
constexpr int64_t count_microseconds (std::chrono::microseconds t)
 
int64_t GetTime ()
 DEPRECATED Use either ClockType::now() or Now<TimePointType>() if a cast is needed. More...
 
void SetMockTime (int64_t nMockTimeIn)
 DEPRECATED Use SetMockTime with chrono type. More...
 
void SetMockTime (std::chrono::seconds mock_time_in)
 For testing. More...
 
std::chrono::seconds GetMockTime ()
 For testing. More...
 
template<typename T >
Now ()
 Return the current time point cast to the given precision. More...
 
template<typename T >
GetTime ()
 DEPRECATED, see GetTime. 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)
 
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...
 

Typedef Documentation

◆ HoursDouble

using HoursDouble = std::chrono::duration<double, std::chrono::hours::period>

Definition at line 60 of file time.h.

◆ MillisecondsDouble

using MillisecondsDouble = std::chrono::duration<double, std::chrono::milliseconds::period>

Definition at line 62 of file time.h.

◆ NodeSeconds

using NodeSeconds = std::chrono::time_point<NodeClock, std::chrono::seconds>

Definition at line 25 of file time.h.

◆ SecondsDouble

using SecondsDouble = std::chrono::duration<double, std::chrono::seconds::period>

Definition at line 61 of file time.h.

◆ SteadyClock

using SteadyClock = std::chrono::steady_clock

Definition at line 27 of file time.h.

◆ SteadyMicroseconds

using SteadyMicroseconds = std::chrono::time_point<std::chrono::steady_clock, std::chrono::microseconds>

Definition at line 30 of file time.h.

◆ SteadyMilliseconds

using SteadyMilliseconds = std::chrono::time_point<std::chrono::steady_clock, std::chrono::milliseconds>

Definition at line 29 of file time.h.

◆ SteadySeconds

using SteadySeconds = std::chrono::time_point<std::chrono::steady_clock, std::chrono::seconds>

Definition at line 28 of file time.h.

◆ SystemClock

using SystemClock = std::chrono::system_clock

Definition at line 32 of file time.h.

Function Documentation

◆ count_microseconds()

constexpr int64_t count_microseconds ( std::chrono::microseconds  t)
constexpr

Definition at line 58 of file time.h.

Here is the caller graph for this function:

◆ count_milliseconds()

constexpr int64_t count_milliseconds ( std::chrono::milliseconds  t)
constexpr

Definition at line 57 of file time.h.

Here is the caller graph for this function:

◆ count_seconds()

constexpr int64_t count_seconds ( std::chrono::seconds  t)
constexpr

Definition at line 56 of file time.h.

Here is the caller graph for this function:

◆ FormatISO8601Date()

std::string FormatISO8601Date ( int64_t  nTime)

Definition at line 58 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 49 of file time.cpp.

Here is the caller graph for this function:

◆ GetMockTime()

std::chrono::seconds GetMockTime ( )

For testing.

Definition at line 42 of file time.cpp.

Here is the caller graph for this function:

◆ GetTime() [1/2]

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 47 of file time.cpp.

Here is the caller graph for this function:

◆ GetTime() [2/2]

template<typename T >
T GetTime ( )

DEPRECATED, see GetTime.

Definition at line 99 of file time.h.

◆ MillisToTimeval() [1/2]

struct timeval MillisToTimeval ( int64_t  nTimeout)

Convert milliseconds to a struct timeval for e.g.

select.

Definition at line 90 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 98 of file time.cpp.

Here is the call graph for this function:

◆ Now()

template<typename T >
T Now ( )

Return the current time point cast to the given precision.

Only use this when an exact precision is needed, otherwise use T::clock::now() directly.

Definition at line 93 of file time.h.

◆ ParseISO8601DateTime()

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

Definition at line 66 of file time.cpp.

Here is the caller graph for this function:

◆ SetMockTime() [1/2]

void SetMockTime ( int64_t  nMockTimeIn)

DEPRECATED Use SetMockTime with chrono type.

Parameters
[in]nMockTimeInTime in seconds.

Definition at line 35 of file time.cpp.

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

◆ SetMockTime() [2/2]

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

For testing.

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

Definition at line 36 of file time.cpp.

◆ Ticks()

template<typename Dur1 , typename Dur2 >
constexpr auto Ticks ( Dur2  d)
constexpr

Helper to count the seconds of a duration/time_point.

All durations/time_points should be using std::chrono and calling this should generally be avoided in code. Though, it is still preferred to an inline t.count() to protect against a reliance on the exact type of t.

This helper is used to convert durations/time_points before passing them over an interface that doesn't support std::chrono (e.g. RPC, debug log, or the GUI)

Definition at line 47 of file time.h.

◆ TicksSinceEpoch()

template<typename Duration , typename Timepoint >
constexpr auto TicksSinceEpoch ( Timepoint  t)
constexpr

Definition at line 52 of file time.h.

◆ UninterruptibleSleep()

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

Definition at line 20 of file time.cpp.

Here is the caller graph for this function: