Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
time.hpp
Go to the documentation of this file.
1#pragma once
2#include <stdint.h>
3#include <fc/string.hpp>
4
5#ifdef _MSC_VER
6 #pragma warning (push)
7 #pragma warning (disable : 4244)
8#endif
9
10namespace fc {
12 public:
13 constexpr explicit microseconds( int64_t c = 0) :_count(c){}
14 static constexpr microseconds maximum() { return microseconds(0x7fffffffffffffffll); }
15 friend constexpr microseconds operator + (const microseconds& l, const microseconds& r ) { return microseconds(l._count+r._count); }
16 friend constexpr microseconds operator - (const microseconds& l, const microseconds& r ) { return microseconds(l._count-r._count); }
17
18 constexpr bool operator==(const microseconds& c)const { return _count == c._count; }
19 constexpr bool operator!=(const microseconds& c)const { return _count != c._count; }
20 friend constexpr bool operator>(const microseconds& a, const microseconds& b){ return a._count > b._count; }
21 friend constexpr bool operator>=(const microseconds& a, const microseconds& b){ return a._count >= b._count; }
22 constexpr friend bool operator<(const microseconds& a, const microseconds& b){ return a._count < b._count; }
23 constexpr friend bool operator<=(const microseconds& a, const microseconds& b){ return a._count <= b._count; }
24 constexpr microseconds& operator+=(const microseconds& c) { _count += c._count; return *this; }
25 constexpr microseconds& operator-=(const microseconds& c) { _count -= c._count; return *this; }
26 constexpr int64_t count()const { return _count; }
27 constexpr int64_t to_seconds()const { return _count/1000000; }
28 private:
29 friend class time_point;
30 int64_t _count;
31 };
32 inline constexpr microseconds seconds( int64_t s ) { return microseconds( s * 1000000 ); }
33 inline constexpr microseconds milliseconds( int64_t s ) { return microseconds( s * 1000 ); }
34 inline constexpr microseconds minutes(int64_t m) { return seconds(60*m); }
35 inline constexpr microseconds hours(int64_t h) { return minutes(60*h); }
36 inline constexpr microseconds days(int64_t d) { return hours(24*d); }
37
38 class variant;
41
42 class time_point {
43 public:
44 constexpr explicit time_point( microseconds e = microseconds() ) :elapsed(e){}
45 static time_point now();
46 static constexpr time_point maximum() { return time_point( microseconds::maximum() ); }
47 static constexpr time_point min() { return time_point(); }
48
49 operator fc::string()const;
50 static time_point from_iso_string( const fc::string& s );
51
52 constexpr const microseconds& time_since_epoch()const { return elapsed; }
53 constexpr uint32_t sec_since_epoch()const { return elapsed.count() / 1000000; }
54 constexpr bool operator > ( const time_point& t )const { return elapsed._count > t.elapsed._count; }
55 constexpr bool operator >=( const time_point& t )const { return elapsed._count >=t.elapsed._count; }
56 constexpr bool operator < ( const time_point& t )const { return elapsed._count < t.elapsed._count; }
57 constexpr bool operator <=( const time_point& t )const { return elapsed._count <=t.elapsed._count; }
58 constexpr bool operator ==( const time_point& t )const { return elapsed._count ==t.elapsed._count; }
59 constexpr bool operator !=( const time_point& t )const { return elapsed._count !=t.elapsed._count; }
60 constexpr time_point& operator += ( const microseconds& m) { elapsed+=m; return *this; }
61 constexpr time_point& operator -= ( const microseconds& m) { elapsed-=m; return *this; }
62 constexpr time_point operator + (const microseconds& m) const { return time_point(elapsed+m); }
63 constexpr time_point operator - (const microseconds& m) const { return time_point(elapsed-m); }
64 constexpr microseconds operator - (const time_point& m) const { return microseconds(elapsed.count() - m.elapsed.count()); }
65 private:
66 microseconds elapsed;
67 };
68
73 {
74 public:
75 constexpr time_point_sec()
76 :utc_seconds(0){}
77
78 constexpr explicit time_point_sec(uint32_t seconds )
79 :utc_seconds(seconds){}
80
81 constexpr time_point_sec( const time_point& t )
82 :utc_seconds( t.time_since_epoch().count() / 1000000ll ){}
83
84 static constexpr time_point_sec maximum() { return time_point_sec(0xffffffff); }
85 static constexpr time_point_sec min() { return time_point_sec(0); }
86
87 constexpr operator time_point()const { return time_point( fc::seconds( utc_seconds) ); }
88 constexpr uint32_t sec_since_epoch()const { return utc_seconds; }
89
91 {
92 utc_seconds = t.time_since_epoch().count() / 1000000ll;
93 return *this;
94 }
95 constexpr friend bool operator < ( const time_point_sec& a, const time_point_sec& b ) { return a.utc_seconds < b.utc_seconds; }
96 constexpr friend bool operator > ( const time_point_sec& a, const time_point_sec& b ) { return a.utc_seconds > b.utc_seconds; }
97 constexpr friend bool operator <= ( const time_point_sec& a, const time_point_sec& b ) { return a.utc_seconds <= b.utc_seconds; }
98 constexpr friend bool operator >= ( const time_point_sec& a, const time_point_sec& b ) { return a.utc_seconds >= b.utc_seconds; }
99 constexpr friend bool operator == ( const time_point_sec& a, const time_point_sec& b ) { return a.utc_seconds == b.utc_seconds; }
100 constexpr friend bool operator != ( const time_point_sec& a, const time_point_sec& b ) { return a.utc_seconds != b.utc_seconds; }
101 constexpr time_point_sec& operator += ( uint32_t m ) { utc_seconds+=m; return *this; }
102 constexpr time_point_sec& operator += ( microseconds m ) { utc_seconds+=m.to_seconds(); return *this; }
103 constexpr time_point_sec& operator -= ( uint32_t m ) { utc_seconds-=m; return *this; }
104 constexpr time_point_sec& operator -= ( microseconds m ) { utc_seconds-=m.to_seconds(); return *this; }
105 constexpr time_point_sec operator +( uint32_t offset )const { return time_point_sec(utc_seconds + offset); }
106 constexpr time_point_sec operator -( uint32_t offset )const { return time_point_sec(utc_seconds - offset); }
107
108 friend constexpr time_point operator + ( const time_point_sec& t, const microseconds& m ) { return time_point(t) + m; }
109 friend constexpr time_point operator - ( const time_point_sec& t, const microseconds& m ) { return time_point(t) - m; }
110 friend constexpr microseconds operator - ( const time_point_sec& t, const time_point_sec& m ) { return time_point(t) - time_point(m); }
111 friend constexpr microseconds operator - ( const time_point& t, const time_point_sec& m ) { return time_point(t) - time_point(m); }
112
115
116 operator fc::string()const;
118
119 private:
120 uint32_t utc_seconds;
121 };
122
123 typedef std::optional<time_point> otime_point;
124
129 const time_point_sec& relative_to_time = fc::time_point::now(),
130 const std::string& ago = " ago");
131 string get_approximate_relative_time_string(const time_point& event_time,
132 const time_point& relative_to_time = fc::time_point::now(),
133 const std::string& ago = " ago");
134}
135
136#include <fc/reflect/reflect.hpp>
140
141#ifdef _MSC_VER
142 #pragma warning (pop)
143#endif
const mie::Vuint & r
Definition bn.cpp:28
constexpr microseconds(int64_t c=0)
Definition time.hpp:13
constexpr bool operator!=(const microseconds &c) const
Definition time.hpp:19
constexpr microseconds & operator-=(const microseconds &c)
Definition time.hpp:25
constexpr int64_t to_seconds() const
Definition time.hpp:27
friend constexpr bool operator>=(const microseconds &a, const microseconds &b)
Definition time.hpp:21
friend constexpr bool operator>(const microseconds &a, const microseconds &b)
Definition time.hpp:20
constexpr int64_t count() const
Definition time.hpp:26
constexpr bool operator==(const microseconds &c) const
Definition time.hpp:18
friend constexpr microseconds operator+(const microseconds &l, const microseconds &r)
Definition time.hpp:15
friend constexpr microseconds operator-(const microseconds &l, const microseconds &r)
Definition time.hpp:16
constexpr microseconds & operator+=(const microseconds &c)
Definition time.hpp:24
constexpr friend bool operator<=(const microseconds &a, const microseconds &b)
Definition time.hpp:23
constexpr friend bool operator<(const microseconds &a, const microseconds &b)
Definition time.hpp:22
static constexpr microseconds maximum()
Definition time.hpp:14
friend constexpr time_point operator-(const time_point_sec &t, const microseconds &m)
Definition time.hpp:109
constexpr friend bool operator==(const time_point_sec &a, const time_point_sec &b)
Definition time.hpp:99
friend constexpr time_point operator+(const time_point_sec &t, const microseconds &m)
Definition time.hpp:108
constexpr time_point_sec()
Definition time.hpp:75
constexpr friend bool operator!=(const time_point_sec &a, const time_point_sec &b)
Definition time.hpp:100
static constexpr time_point_sec min()
Definition time.hpp:85
static constexpr time_point_sec maximum()
Definition time.hpp:84
constexpr friend bool operator>(const time_point_sec &a, const time_point_sec &b)
Definition time.hpp:96
constexpr time_point_sec & operator+=(uint32_t m)
Definition time.hpp:101
fc::string to_iso_string() const
Definition time.cpp:28
constexpr uint32_t sec_since_epoch() const
Definition time.hpp:88
constexpr time_point_sec & operator-=(uint32_t m)
Definition time.hpp:103
static time_point_sec from_iso_string(const fc::string &s)
Definition time.cpp:39
constexpr friend bool operator<=(const time_point_sec &a, const time_point_sec &b)
Definition time.hpp:97
constexpr time_point_sec(const time_point &t)
Definition time.hpp:81
constexpr friend bool operator<(const time_point_sec &a, const time_point_sec &b)
Definition time.hpp:95
constexpr friend bool operator>=(const time_point_sec &a, const time_point_sec &b)
Definition time.hpp:98
fc::string to_non_delimited_iso_string() const
Definition time.cpp:22
constexpr time_point_sec(uint32_t seconds)
Definition time.hpp:78
constexpr time_point_sec operator=(const fc::time_point &t)
Definition time.hpp:90
constexpr bool operator<(const time_point &t) const
Definition time.hpp:56
constexpr bool operator<=(const time_point &t) const
Definition time.hpp:57
constexpr time_point & operator-=(const microseconds &m)
Definition time.hpp:61
constexpr uint32_t sec_since_epoch() const
Definition time.hpp:53
static constexpr time_point min()
Definition time.hpp:47
constexpr time_point & operator+=(const microseconds &m)
Definition time.hpp:60
static time_point now()
Definition time.cpp:14
constexpr time_point operator-(const microseconds &m) const
Definition time.hpp:63
constexpr time_point(microseconds e=microseconds())
Definition time.hpp:44
constexpr const microseconds & time_since_epoch() const
Definition time.hpp:52
constexpr bool operator!=(const time_point &t) const
Definition time.hpp:59
constexpr bool operator>=(const time_point &t) const
Definition time.hpp:55
static time_point from_iso_string(const fc::string &s)
Definition time.cpp:67
constexpr time_point operator+(const microseconds &m) const
Definition time.hpp:62
constexpr bool operator>(const time_point &t) const
Definition time.hpp:54
static constexpr time_point maximum()
Definition time.hpp:46
constexpr bool operator==(const time_point &t) const
Definition time.hpp:58
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
Definition variant.hpp:191
int * count
namespace sysio::chain
Definition authority.cpp:3
std::optional< time_point > otime_point
Definition time.hpp:123
std::string string
Definition string.hpp:10
constexpr microseconds hours(int64_t h)
Definition time.hpp:35
constexpr microseconds milliseconds(int64_t s)
Definition time.hpp:33
constexpr microseconds seconds(int64_t s)
Definition time.hpp:32
constexpr microseconds minutes(int64_t m)
Definition time.hpp:34
string get_approximate_relative_time_string(const time_point_sec &event_time, const time_point_sec &relative_to_time=fc::time_point::now(), const std::string &ago=" ago")
Definition time.cpp:94
void from_variant(const fc::variant &v, sysio::chain::chain_id_type &cid)
constexpr microseconds days(int64_t d)
Definition time.hpp:36
void to_variant(const sysio::chain::shared_public_key &var, fc::variant &vo)
Definition authority.cpp:4
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181
#define FC_REFLECT_TYPENAME(TYPE)
Definition reflect.hpp:320
signed __int64 int64_t
Definition stdint.h:135
unsigned int uint32_t
Definition stdint.h:126
CK_ULONG d
char * s
int l