Skip to content
Snippets Groups Projects
Commit 53831eea authored by Martí Morta Garriga's avatar Martí Morta Garriga
Browse files

Added ref time function

parent 6196f725
No related branches found
No related tags found
No related merge requests found
...@@ -128,8 +128,12 @@ void CTime::set(double milliseconds) ...@@ -128,8 +128,12 @@ void CTime::set(double milliseconds)
this->nsec = time_temp.tv_nsec; this->nsec = time_temp.tv_nsec;
if(this->use_zero && milliseconds<0.0) if(this->use_zero && milliseconds<0.0)
{ {
this->sec -= this->zero.seconds(); CTime tmp;
this->nsec -= this->zero.nanoseconds(); tmp.sec = this->sec;
tmp.nsec = this->nsec;
tmp = diff(tmp,this->zero);
this->sec = tmp.sec;
this->nsec = tmp.nsec;
} }
} }
...@@ -153,6 +157,21 @@ void CTime::resetRef() ...@@ -153,6 +157,21 @@ void CTime::resetRef()
void CTime::useRef(bool use) void CTime::useRef(bool use)
{ {
this->use_zero = use; this->use_zero = use;
CTime tmp;
tmp.sec = this->sec;
tmp.nsec = this->nsec;
tmp = diff(tmp,this->zero);
this->sec = tmp.sec;
this->nsec = tmp.nsec;
/*
if ( (long)this->nsec - (long)this->zero.seconds() < 0 )
{
this->sec -= this->zero.seconds() - 1;
this->nsec += 1000000000 - this->zero.nanoseconds();
} else {
this->sec -= this->zero.seconds();
this->nsec -= this->zero.nanoseconds();
}*/
} }
bool CTime::isRefUsed() bool CTime::isRefUsed()
...@@ -160,23 +179,40 @@ bool CTime::isRefUsed() ...@@ -160,23 +179,40 @@ bool CTime::isRefUsed()
return this->use_zero; return this->use_zero;
} }
// OPERATIONS CTime CTime::diff(CTime &t0, CTime &t1)
CTime CTime::operator - (CTime &t)
{ {
CTime tmp; CTime tmp;
tmp = t0;
if ( (long)this->nsec - (long)t.nsec < 0 ) if ( (long)t0.nsec - (long)t1.sec < 0 )
{ {
tmp.sec = this->sec - t.sec - 1; tmp.sec -= t1.sec - 1;
tmp.nsec = 1000000000 + this->nsec - t.nsec; tmp.nsec += 1000000000 - t1.nsec;
} else { } else {
tmp.sec = this->sec - t.sec; tmp.sec -= t1.sec;
tmp.nsec = this->nsec - t.nsec; tmp.nsec -= t1.nsec;
} }
return tmp; return tmp;
} }
// OPERATIONS
CTime CTime::operator - (CTime &t)
{
CTime tmp;
tmp.sec=this->sec;
tmp.nsec=this->nsec;
// if ( (long)this->nsec - (long)t.nsec < 0 )
// {
// tmp.sec = this->sec - t.sec - 1;
// tmp.nsec = 1000000000 + this->nsec - t.nsec;
// } else {
// tmp.sec = this->sec - t.sec;
// tmp.nsec = this->nsec - t.nsec;
// }
return diff(tmp,t);
}
CTime CTime::operator + (CTime &t) CTime CTime::operator + (CTime &t)
{ {
CTime tmp; CTime tmp;
......
...@@ -310,6 +310,8 @@ class CTime ...@@ -310,6 +310,8 @@ class CTime
*/ */
void resetRef(); void resetRef();
CTime diff(CTime &t0, CTime &t1);
///@} ///@}
/// @name Operators /// @name Operators
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment