rippled
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 <date/date.h>
24 
25 #include <ripple/beast/clock/abstract_clock.h>
26 #include <ripple/beast/clock/basic_seconds_clock.h>
27 #include <ripple/beast/clock/manual_clock.h>
28 #include <chrono>
29 #include <cstdint>
30 #include <string>
31 
32 namespace ripple {
33 
34 // A few handy aliases
35 
37  int,
39 
40 using weeks = std::chrono::
41  duration<int, std::ratio_multiply<days::period, std::ratio<7>>>;
42 
48 class NetClock
49 {
50 public:
51  explicit NetClock() = default;
52 
53  using rep = std::uint32_t;
57 
58  static bool const is_steady = false;
59 };
60 
61 template <class Duration>
63 to_string(date::sys_time<Duration> tp)
64 {
65  return date::format("%Y-%b-%d %T %Z", tp);
66 }
67 
68 inline std::string
70 {
71  // 2000-01-01 00:00:00 UTC is 946684800s from 1970-01-01 00:00:00 UTC
72  using namespace std::chrono;
73  return to_string(
74  system_clock::time_point{tp.time_since_epoch() + 946684800s});
75 }
76 
82 
85 
87 inline Stopwatch&
89 {
90  using Clock = beast::basic_seconds_clock;
91  using Facade = Clock::Clock;
92  return beast::get_abstract_clock<Facade, Clock>();
93 }
94 
95 } // namespace ripple
96 
97 #endif
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:88
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:36
std::ratio
chrono
std::chrono::time_point
cstdint
std::uint32_t
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:58
ripple::to_string
std::string to_string(Manifest const &m)
Format the specified manifest to a string for debugging purposes.
Definition: app/misc/impl/Manifest.cpp:41
ripple::days
std::chrono::duration< int, std::ratio_multiply< std::chrono::hours::period, std::ratio< 24 > >> days
Definition: chrono.h:38
beast::manual_clock< std::chrono::steady_clock >
ripple::NetClock
Clock for measuring the network time.
Definition: chrono.h:48
std::ratio_multiply
std::chrono
string