update to time

This commit is contained in:
Daniel Larimer 2012-10-17 22:44:21 -04:00
parent 1de7c609fa
commit 62f7d99b6e
2 changed files with 12 additions and 0 deletions

View file

@ -1,6 +1,7 @@
#ifndef _FC_TIME_HPP_
#define _FC_TIME_HPP_
#include <stdint.h>
#include <fc/string.hpp>
namespace fc {
class microseconds {
@ -26,6 +27,8 @@ namespace fc {
static time_point now();
static time_point max() { return time_point( microseconds::max() ); }
static time_point min() { return time_point(); }
operator fc::string()const;
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; }

View file

@ -1,9 +1,18 @@
#include <boost/chrono/system_clocks.hpp>
#include <fc/time.hpp>
#include <sstream>
namespace fc {
namespace bch = boost::chrono;
time_point time_point::now() {
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();
}
}