Implement assignment by subtraction for time classes
This commit is contained in:
parent
7ca061fb03
commit
cde67a202c
1 changed files with 9 additions and 6 deletions
|
|
@ -9,7 +9,7 @@
|
|||
#endif //// _MSC_VER
|
||||
|
||||
namespace fc {
|
||||
class microseconds {
|
||||
class microseconds {
|
||||
public:
|
||||
explicit microseconds( int64_t c = 0) :_count(c){}
|
||||
static microseconds maximum() { return microseconds(0x7fffffffffffffffll); }
|
||||
|
|
@ -23,10 +23,11 @@ namespace fc {
|
|||
friend bool operator<(const microseconds& a, const microseconds& b){ return a._count < b._count; }
|
||||
friend bool operator<=(const microseconds& a, const microseconds& b){ return a._count <= b._count; }
|
||||
microseconds& operator+=(const microseconds& c) { _count += c._count; return *this; }
|
||||
microseconds& operator-=(const microseconds& c) { _count -= c._count; return *this; }
|
||||
int64_t count()const { return _count; }
|
||||
private:
|
||||
friend class time_point;
|
||||
int64_t _count;
|
||||
int64_t _count;
|
||||
};
|
||||
inline microseconds seconds( int64_t s ) { return microseconds( s * 1000000 ); }
|
||||
inline microseconds milliseconds( int64_t s ) { return microseconds( s * 1000 ); }
|
||||
|
|
@ -34,14 +35,14 @@ namespace fc {
|
|||
inline microseconds hours(int64_t h) { return minutes(60*h); }
|
||||
inline microseconds days(int64_t d) { return hours(24*d); }
|
||||
|
||||
class time_point {
|
||||
class time_point {
|
||||
public:
|
||||
explicit time_point( microseconds e = microseconds() ) :elapsed(e){}
|
||||
static time_point now();
|
||||
static time_point maximum() { return time_point( microseconds::maximum() ); }
|
||||
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; }
|
||||
|
|
@ -53,17 +54,18 @@ namespace fc {
|
|||
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; }
|
||||
time_point& operator += ( const microseconds& m) { elapsed+=m; return *this; }
|
||||
time_point& operator -= ( const microseconds& m) { elapsed-=m; return *this; }
|
||||
time_point operator + (const microseconds& m) const { return time_point(elapsed+m); }
|
||||
time_point operator - (const microseconds& m) const { return time_point(elapsed-m); }
|
||||
microseconds operator - (const time_point& m) const { return microseconds(elapsed.count() - m.elapsed.count()); }
|
||||
private:
|
||||
microseconds elapsed;
|
||||
microseconds elapsed;
|
||||
};
|
||||
|
||||
/**
|
||||
* A lower resolution time_point accurate only to seconds from 1970
|
||||
*/
|
||||
class time_point_sec
|
||||
class time_point_sec
|
||||
{
|
||||
public:
|
||||
time_point_sec()
|
||||
|
|
@ -90,6 +92,7 @@ namespace fc {
|
|||
friend bool operator == ( const time_point_sec& a, const time_point_sec& b ) { return a.utc_seconds == b.utc_seconds; }
|
||||
friend bool operator != ( const time_point_sec& a, const time_point_sec& b ) { return a.utc_seconds != b.utc_seconds; }
|
||||
time_point_sec& operator += ( uint32_t m ) { utc_seconds+=m; return *this; }
|
||||
time_point_sec& operator -= ( uint32_t m ) { utc_seconds-=m; return *this; }
|
||||
|
||||
friend time_point operator - ( const time_point_sec& t, const microseconds& m ) { return time_point(t) - m; }
|
||||
friend microseconds operator - ( const time_point_sec& t, const time_point_sec& m ) { return time_point(t) - time_point(m); }
|
||||
|
|
|
|||
Loading…
Reference in a new issue