update to time
This commit is contained in:
parent
1de7c609fa
commit
62f7d99b6e
2 changed files with 12 additions and 0 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
#ifndef _FC_TIME_HPP_
|
#ifndef _FC_TIME_HPP_
|
||||||
#define _FC_TIME_HPP_
|
#define _FC_TIME_HPP_
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <fc/string.hpp>
|
||||||
|
|
||||||
namespace fc {
|
namespace fc {
|
||||||
class microseconds {
|
class microseconds {
|
||||||
|
|
@ -26,6 +27,8 @@ namespace fc {
|
||||||
static time_point now();
|
static time_point now();
|
||||||
static time_point max() { return time_point( microseconds::max() ); }
|
static time_point max() { return time_point( microseconds::max() ); }
|
||||||
static time_point min() { return time_point(); }
|
static time_point min() { return time_point(); }
|
||||||
|
operator fc::string()const;
|
||||||
|
|
||||||
const microseconds& time_since_epoch()const { return elapsed; }
|
const microseconds& time_since_epoch()const { return elapsed; }
|
||||||
bool operator > ( const time_point& t )const { return elapsed._count > t.elapsed._count; }
|
bool operator > ( const time_point& t )const { return elapsed._count > t.elapsed._count; }
|
||||||
bool operator < ( const time_point& t )const { return elapsed._count < t.elapsed._count; }
|
bool operator < ( const time_point& t )const { return elapsed._count < t.elapsed._count; }
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,18 @@
|
||||||
#include <boost/chrono/system_clocks.hpp>
|
#include <boost/chrono/system_clocks.hpp>
|
||||||
#include <fc/time.hpp>
|
#include <fc/time.hpp>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
namespace fc {
|
namespace fc {
|
||||||
namespace bch = boost::chrono;
|
namespace bch = boost::chrono;
|
||||||
time_point time_point::now() {
|
time_point time_point::now() {
|
||||||
return time_point(microseconds(bch::duration_cast<bch::microseconds>(bch::system_clock::now().time_since_epoch()).count()));
|
return time_point(microseconds(bch::duration_cast<bch::microseconds>(bch::system_clock::now().time_since_epoch()).count()));
|
||||||
}
|
}
|
||||||
|
time_point::operator fc::string()const {
|
||||||
|
bch::system_clock::time_point tp;
|
||||||
|
tp += bch::microseconds( elapsed._count);
|
||||||
|
time_t tt = bch::system_clock::to_time_t(tp);
|
||||||
|
std::stringstream ss;
|
||||||
|
ss<<tt;
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue