bool RealTime::operator >(const RealTime &t) const { if (GetSec() > t.GetSec()) return true; if (GetSec() == t.GetSec() && GetUsec() > t.GetUsec()) return true; return false; }
RealTime RealTime::operator +(int msec) const { int usec = GetUsec() + msec * 1000; if (usec >= ONE_MILLION) { return RealTime(GetSec() + usec / ONE_MILLION, usec % ONE_MILLION); } else { return RealTime(GetSec(), usec); } }
RealTime RealTime::operator +(const RealTime &t) const { if (GetUsec() + t.GetUsec() >= ONE_MILLION) { return RealTime(GetSec() + t.GetSec() + 1, GetUsec() + t.GetUsec() - ONE_MILLION); } else { return RealTime(GetSec() + t.GetSec(), GetUsec() + t.GetUsec()); } }
RealTime RealTime::operator -(int msec) const { int usec = GetUsec() - msec * 1000; if (usec < 0) { usec = -usec; return RealTime(GetSec() - usec / ONE_MILLION - 1, ONE_MILLION - usec % ONE_MILLION); } else { return RealTime(GetSec(), usec); } }
/** GetMicro() ger antalet microsekunder **/ double Timer::GetMicro(){ #ifdef _WIN32 QueryPerformanceCounter(&nEnd); QueryPerformanceFrequency(&nFreq); return (nEnd.QuadPart - nStart.QuadPart) * 1e6/nFreq.QuadPart; #else gettimeofday(&tEnd, NULL); return (GetSec() * 1E6) + (tEnd.tv_usec - tStart.tv_usec); #endif }
inline string _time_xtd::ToStdString() const { //rivedi x rendere + snello string convertita = ""; ostringstream out; out.fill('0'); out.width(2); out << GetHour(); out.width(1); out << ':'; out.fill('0'); out.width(2); out << GetMin(); out.width(1); out << ':'; out.fill('0'); out.width(2); out << GetSec(); convertita = out.str(); return convertita; }
std::wstring CDealTime::Format(LPCTSTR format) { std::wstring strResult; std::wstring tempFormat(format); std::wstring::size_type posY = tempFormat.find(_T("%Y")); if(posY != tempFormat.npos) { UINT year = GetYear(); wchar_t wtYear[5]={0}; swprintf_s(wtYear,_T("%d"),year); // tempFormat.replace(posY,posY+2,wtYear,4); strResult += wtYear; } wstring::size_type posM = tempFormat.find(_T("%M")); if(posM != tempFormat.npos) { UINT month = GetMonth(); wchar_t wtMonth[3]={0}; swprintf_s(wtMonth,_T("%d"),month); wstring subStr = tempFormat.substr(posY+2,posM-posY-2); strResult += subStr; strResult += wtMonth; // tempFormat.replace(posM,posM+2,wtMonth,2); } wstring::size_type posD = tempFormat.find(_T("%D")); if(posD != tempFormat.npos) { UINT day = GetDay(); wchar_t wtDay[3]={0}; swprintf_s(wtDay,_T("%d"),day); // tempFormat.replace(posD,posD+2,wtDay,2); wstring subStr = tempFormat.substr(posM+2,posD-posM-2); strResult += subStr; strResult += wtDay; } wstring::size_type posH = tempFormat.find(_T("%H")); if(posH != tempFormat.npos) { UINT hour = GetHour(); wchar_t wtHour[3]={0}; swprintf_s(wtHour,_T("%d"),hour); // tempFormat.replace(posH,posH+2,wtHour,2); wstring subStr = tempFormat.substr(posD+2,posH-posD-2); strResult += subStr; strResult += wtHour; } wstring::size_type posMin = tempFormat.find(_T("%m")); if(posMin != tempFormat.npos) { UINT Min = GetMin(); wchar_t wtMin[3]={0}; swprintf_s(wtMin,_T("%d"),Min); wstring subStr = tempFormat.substr(posH+2,posMin-posH-2); strResult += subStr; strResult += wtMin; // tempFormat.replace(posMin,posMin+2,wtMin,2); } wstring::size_type posS = tempFormat.find(_T("%S")); if(posS != tempFormat.npos) { UINT Sec = GetSec(); wchar_t wtSec[3]={0}; swprintf_s(wtSec,_T("%d"),Sec); // tempFormat.replace(posS,posS+2,wtSec,2); wstring subStr = tempFormat.substr(posMin+2,posS-posMin-2); strResult += subStr; strResult += wtSec; } return strResult; }
long RealTime::Sub(const RealTime &t) { return (GetSec() - t.GetSec()) * 1000000 + GetUsec() - t.GetUsec(); }
int RealTime::operator -(const RealTime &t) const { return (GetSec() - t.GetSec()) * 1000 + int((GetUsec() - t.GetUsec()) / 1000.0); }