rippled
ripple
basics
chrono.h
1
//------------------------------------------------------------------------------
2
/*
3
This file is part of rippled: https://github.com/ripple/rippled
4
Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6
Permission to use, copy, modify, and/or distribute this software for any
7
purpose with or without fee is hereby granted, provided that the above
8
copyright notice and this permission notice appear in all copies.
9
10
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
*/
18
//==============================================================================
19
20
#ifndef RIPPLE_BASICS_CHRONO_H_INCLUDED
21
#define RIPPLE_BASICS_CHRONO_H_INCLUDED
22
23
#include <ripple/beast/clock/abstract_clock.h>
24
#include <ripple/beast/clock/basic_seconds_clock.h>
25
#include <ripple/beast/clock/manual_clock.h>
26
#include <
chrono
>
27
#include <
cstdint
>
28
#include <
string
>
29
30
namespace
ripple
{
31
32
// A few handy aliases
33
34
using
days
=
std::chrono::duration
<
35
int,
36
std::ratio_multiply<std::chrono::hours::period, std::ratio<24>
>>;
37
38
using
weeks
= std::chrono::
39
duration<int, std::ratio_multiply<days::period, std::ratio<7>>>;
40
46
class
NetClock
47
{
48
public
:
49
explicit
NetClock
() =
default
;
50
51
using
rep
=
std::uint32_t
;
52
using
period
=
std::ratio<1>
;
53
using
duration
=
std::chrono::duration<rep, period>
;
54
using
time_point
=
std::chrono::time_point<NetClock>
;
55
56
static
bool
const
is_steady
=
false
;
57
};
58
59
template
<
class
Duration>
60
std::string
61
to_string
(date::sys_time<Duration> tp)
62
{
63
return
date::format(
"%Y-%b-%d %T %Z"
, tp);
64
}
65
66
inline
std::string
67
to_string
(
NetClock::time_point
tp)
68
{
69
// 2000-01-01 00:00:00 UTC is 946684800s from 1970-01-01 00:00:00 UTC
70
using namespace
std::chrono
;
71
return
to_string
(
72
system_clock::time_point{tp.
time_since_epoch
() + 946684800s});
73
}
74
79
using
Stopwatch
=
beast::abstract_clock<std::chrono::steady_clock>
;
80
82
using
TestStopwatch
=
beast::manual_clock<std::chrono::steady_clock>
;
83
85
inline
Stopwatch
&
86
stopwatch
()
87
{
88
return
beast::get_abstract_clock
<
89
std::chrono::steady_clock
,
90
beast::basic_seconds_clock<std::chrono::steady_clock>
>();
91
}
92
93
}
// namespace ripple
94
95
#endif
std::chrono::steady_clock
std::string
STL class.
std::chrono::duration
ripple::NetClock::NetClock
NetClock()=default
ripple::stopwatch
Stopwatch & stopwatch()
Returns an instance of a wall clock.
Definition:
chrono.h:86
ripple::to_string
std::string to_string(ListDisposition disposition)
Definition:
ValidatorList.cpp:45
std::chrono::time_point::time_since_epoch
T time_since_epoch(T... args)
beast::basic_seconds_clock
A clock whose minimum resolution is one second.
Definition:
basic_seconds_clock.h:147
std::ratio
chrono
std::chrono::time_point
cstdint
std::uint32_t
beast::get_abstract_clock
abstract_clock< Facade > & get_abstract_clock()
Returns a global instance of an abstract clock.
Definition:
abstract_clock.h:107
beast::abstract_clock< std::chrono::steady_clock >
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition:
RCLCensorshipDetector.h:29
ripple::NetClock::is_steady
static const bool is_steady
Definition:
chrono.h:56
ripple::days
std::chrono::duration< int, std::ratio_multiply< std::chrono::hours::period, std::ratio< 24 > >> days
Definition:
chrono.h:36
beast::manual_clock< std::chrono::steady_clock >
ripple::NetClock
Clock for measuring Ripple Network Time.
Definition:
chrono.h:46
std::ratio_multiply
std::chrono
string
Generated by
1.8.17