time /string conversion

This commit is contained in:
Daniel Larimer 2013-01-20 15:44:16 -05:00
parent 21ef2d11e9
commit cc44e8bbe0
4 changed files with 15 additions and 1 deletions

View file

@ -1,5 +1,6 @@
#pragma once
#include <fc/shared_ptr.hpp>
#include <fc/filesystem.hpp>
#include <fc/iostream.hpp>
namespace fc {

View file

@ -30,6 +30,8 @@ namespace fc {
static time_point min() { return time_point(); }
operator fc::string()const;
static time_point from_iso_string( const fc::string& s );
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

@ -14,4 +14,15 @@ namespace fc {
time_t tt = bch::system_clock::to_time_t(tp);
return boost::posix_time::to_iso_string( boost::posix_time::from_time_t(tt) );
}
time_point time_point::from_iso_string( const fc::string& s ) {
auto pt = boost::posix_time::from_iso_string(s);
return fc::time_point(fc::seconds( (pt - boost::posix_time::from_time_t(0)).total_seconds() ));
}
class value;
void pack( fc::value& v, const fc::time_point& t ) {
v = fc::string(t);
}
void unpack( const fc::value& v, fc::time_point& t ) {
t = fc::time_point::from_iso_string(v.cast<fc::string>());
}
}

View file

@ -1,3 +1,3 @@
add_subdirectory( libssh2-1.4.2 )
#add_subdirectory( zlib-1.2.7)
add_subdirectory( sigar )
#add_subdirectory( sigar )