cmn_Time Class Reference
[Common, basic classes, functions and types]

#include <cmn_time.h>

List of all members.


Detailed Description

Definition at line 23 of file cmn_time.h.


Public Member Functions

 cmn_Time ()
 cmn_Time (time_t a_time, unsigned short a_mili=0, bool a_UTC=false)
 cmn_Time (const string a_time)
 ~cmn_Time ()
cmn_Time operator- (const cmn_Time &t1)
cmn_Timeoperator-= (const cmn_Time &t1)
void Refresh ()
time_t GetTime_t ()
unsigned short GetMilliTime ()
UInt64_t GetTimeInMiliSec ()
UInt64_t GetTimeInMicroSec ()
char * c_Time2YMDhmsm () const
char * c_Time2YMDhms () const
char * c_Time2YMD () const
char * c_Time2hmsm () const
char * c_Time2hms () const
char * c_Time2hm () const
string Time2YMDhmsm () const
string Time2YMDhms () const
string Time2YMD () const
string Time2hmsm () const
string Time2hms () const
string Time2hm () const

Public Attributes

 log_CLASSID_m

Private Member Functions

void TimeToFields ()
void TimeToFieldsUTC ()

Private Attributes

struct timeb m_MilliTime
struct tm m_TimeFields
char m_buf [32]

Constructor & Destructor Documentation

cmn_Time::cmn_Time (  ) 

Definition at line 40 of file cmn_Time.cpp.

References Refresh().

Referenced by operator-().

00040                    {
00041     Refresh();
00042 }

Here is the call graph for this function:

Here is the caller graph for this function:

cmn_Time::cmn_Time ( time_t  a_time,
unsigned short  a_mili = 0,
bool  a_UTC = false 
)

Definition at line 44 of file cmn_Time.cpp.

References ivd_FTime, m_MilliTime, TimeToFields(), and TimeToFieldsUTC().

00044                                                                    {
00045     ivd_FTime(&m_MilliTime);        // to get proper timezone
00046     m_MilliTime.time    = a_time;
00047     m_MilliTime.millitm = a_mili;
00048     if (a_UTC) {
00049         TimeToFieldsUTC();
00050     }
00051     else {
00052         TimeToFields();
00053     }
00054 }

Here is the call graph for this function:

cmn_Time::cmn_Time ( const string  a_time  ) 

Definition at line 57 of file cmn_Time.cpp.

References cmn_Num2Str(), ie_NOT_VALID, ivd_Error, log_FUNC_m, m_MilliTime, m_TimeFields, min, and mktime().

00057                                       {
00058 
00059     log_FUNC_m(cmn_Time);
00060 
00061     string strDate(""); //string up to first space
00062     string strTime(""); //string after first spacehole
00063 
00064     size_t spacePos;
00065     spacePos = a_time.find(" ", 0);
00066     strDate = a_time.substr(0, spacePos);
00067 
00068     if (strDate.length() < a_time.length() ) {
00069         spacePos = a_time.find_last_of(" " ,spacePos);
00070         strTime = a_time.substr(spacePos+1, a_time.length());
00071     }
00072 
00073     int year = 0, month = 0 , day = 0;
00074     int errCode = sscanf(strDate.c_str(), "%d/%d/%d", &year, &month, &day);
00075 
00076     int hour = 0, min = 0 , sec = 0;
00077     if  (errCode == 3) {
00078         if  (strTime.length() > 0) {
00079             errCode = sscanf(strTime.c_str(), "%d:%d:%d", &hour, &min, &sec);
00080             if (errCode < 3) {
00081                 throw ivd_Error(ie_NOT_VALID, "Time: wrong=" + strTime);
00082             }
00083         }
00084     } else {
00085         throw ivd_Error(ie_NOT_VALID, "Date: wrong=" + strDate);
00086     }
00087 
00088     if (year >= 1900) {
00089         m_TimeFields.tm_year = year - 1900;
00090     } else throw ivd_Error(ie_NOT_VALID, "Year: wrong=" + cmn_Num2Str(year));
00091 
00092     if ((month > 0) && (month <= 12)) {
00093         m_TimeFields.tm_mon = month - 1;
00094     } else throw ivd_Error(ie_NOT_VALID, "Month: wrong=" + cmn_Num2Str(month));
00095 
00096     if ((day > 0) && (day <= 31)) {
00097         m_TimeFields.tm_mday = day;
00098     } else throw ivd_Error(ie_NOT_VALID, "Day: wrong=" + cmn_Num2Str(day));
00099 
00100     if ((hour >= 0) && (hour < 24)) {
00101         m_TimeFields.tm_hour = hour;
00102     } else throw ivd_Error(ie_NOT_VALID, "Hour: wrong=" + cmn_Num2Str(hour));
00103 
00104     if ((min >= 0) && (min <= 59)) {
00105         m_TimeFields.tm_min = min;
00106     } else throw ivd_Error(ie_NOT_VALID, "Min: wrong=" + cmn_Num2Str(min));
00107 
00108     if ((sec >= 0) && (sec <= 59)) {
00109         m_TimeFields.tm_sec = sec;
00110     } else throw ivd_Error(ie_NOT_VALID, "Sec: wrong=" + cmn_Num2Str(sec));
00111 
00112     m_TimeFields.tm_isdst = -1;
00113     m_MilliTime.time = mktime( &m_TimeFields);
00114     m_MilliTime.millitm = 0;
00115 }

Here is the call graph for this function:

cmn_Time::~cmn_Time (  )  [inline]

Definition at line 30 of file cmn_time.h.

00030 {};


Member Function Documentation

cmn_Time cmn_Time::operator- ( const cmn_Time t1  ) 

Definition at line 117 of file cmn_Time.cpp.

References cmn_Time().

00117                                                   {
00118     return cmn_Time(*this) -= t1;
00119 }

Here is the call graph for this function:

cmn_Time & cmn_Time::operator-= ( const cmn_Time t1  ) 

Definition at line 121 of file cmn_Time.cpp.

References m_MilliTime, and TimeToFieldsUTC().

00121                                                    {
00122 
00123     if (m_MilliTime.millitm < t1.m_MilliTime.millitm) {
00124         m_MilliTime.millitm += (1000 - t1.m_MilliTime.millitm);
00125         m_MilliTime.time    -= (t1.m_MilliTime.time + 1);
00126     }
00127     else {
00128         m_MilliTime.millitm -= t1.m_MilliTime.millitm;
00129         m_MilliTime.time    -= t1.m_MilliTime.time;
00130     }
00131 
00132     TimeToFieldsUTC();  // relative time is need. don't use location
00133     return *this;
00134 }

Here is the call graph for this function:

void cmn_Time::Refresh (  ) 

Definition at line 136 of file cmn_Time.cpp.

References ivd_FTime, m_MilliTime, and TimeToFields().

Referenced by TreeWalk::CheckDir(), cmn_Time(), and TreeWalk::TreeWalk().

00136                        {
00137     ivd_FTime(&m_MilliTime);
00138     TimeToFields();
00139 }

Here is the call graph for this function:

Here is the caller graph for this function:

time_t cmn_Time::GetTime_t (  )  [inline]

unsigned short cmn_Time::GetMilliTime (  )  [inline]

UInt64_t cmn_Time::GetTimeInMiliSec (  )  [inline]

Definition at line 69 of file cmn_time.h.

Referenced by Rate().

00069                                 { 
00070         return ((UInt64_t)m_MilliTime.time * 1000 + m_MilliTime.millitm); };

Here is the caller graph for this function:

UInt64_t cmn_Time::GetTimeInMicroSec (  )  [inline]

Definition at line 71 of file cmn_time.h.

Referenced by TreeWalk::CheckDir().

00071 { return ((UInt64_t)m_MilliTime.time * 1000 + m_MilliTime.millitm) * 1000; };

Here is the caller graph for this function:

char * cmn_Time::c_Time2YMDhmsm (  )  const

Definition at line 184 of file cmn_Time.cpp.

References m_buf, m_MilliTime, and m_TimeFields.

Referenced by log_Debugger::WriteHeader().

00184                                      {
00185     sprintf(m_buf,"%4d/%02d/%02d %02d:%02d:%02d.%03d",
00186         m_TimeFields.tm_year,
00187         m_TimeFields.tm_mon,
00188         m_TimeFields.tm_mday,
00189         m_TimeFields.tm_hour,
00190         m_TimeFields.tm_min,
00191         m_TimeFields.tm_sec,
00192         m_MilliTime.millitm);
00193     return m_buf;
00194 }

Here is the caller graph for this function:

char * cmn_Time::c_Time2YMDhms (  )  const

Definition at line 196 of file cmn_Time.cpp.

References m_buf, and m_TimeFields.

Referenced by ui_MsgWriter::DisplayMessage(), i_ManagementInterface_i::ListDrives(), i_ManagementInterface_i::ListLibraries(), and i_ManagementInterface_i::ListMediumVolumes().

00196                                     {
00197     sprintf(m_buf,"%4d/%02d/%02d %02d:%02d:%02d",
00198         m_TimeFields.tm_year,
00199         m_TimeFields.tm_mon,
00200         m_TimeFields.tm_mday,
00201         m_TimeFields.tm_hour,
00202         m_TimeFields.tm_min,
00203         m_TimeFields.tm_sec);
00204     return m_buf;
00205 }

Here is the caller graph for this function:

char * cmn_Time::c_Time2YMD (  )  const

Definition at line 207 of file cmn_Time.cpp.

References m_buf, and m_TimeFields.

00207                                  {
00208     sprintf(m_buf,"%4d/%02d/%02d",
00209         m_TimeFields.tm_year,
00210         m_TimeFields.tm_mon,
00211         m_TimeFields.tm_mday);
00212     return m_buf;
00213 }

char * cmn_Time::c_Time2hmsm (  )  const

Definition at line 215 of file cmn_Time.cpp.

References m_buf, m_MilliTime, and m_TimeFields.

Referenced by log_Debugger::WriteHeader().

00215                                   {
00216     sprintf(m_buf,"%02d:%02d:%02d.%03d",
00217         m_TimeFields.tm_hour,
00218         m_TimeFields.tm_min,
00219         m_TimeFields.tm_sec,
00220         m_MilliTime.millitm);
00221     return m_buf;
00222 }

Here is the caller graph for this function:

char * cmn_Time::c_Time2hms (  )  const

Definition at line 224 of file cmn_Time.cpp.

References m_buf, and m_TimeFields.

00224                                  {
00225     sprintf(m_buf,"%02d:%02d:%02d",
00226         m_TimeFields.tm_hour,
00227         m_TimeFields.tm_min,
00228         m_TimeFields.tm_sec);
00229     return m_buf;
00230 }

char * cmn_Time::c_Time2hm (  )  const

Definition at line 232 of file cmn_Time.cpp.

References m_buf, and m_TimeFields.

00232                                 {
00233     sprintf(m_buf,"%02d:%02d",
00234         m_TimeFields.tm_hour,
00235         m_TimeFields.tm_min);
00236     return m_buf;
00237 }

string cmn_Time::Time2YMDhmsm (  )  const [inline]

Definition at line 79 of file cmn_time.h.

Referenced by log_Debugger::ChangeParams(), ut_Group::Header(), ut_Basic::Header(), log_Output(), log_Debugger::Off(), log_Debugger::On(), operator<<(), and job_Manager::RemoveFromList().

00079 { return c_Time2YMDhmsm();};

Here is the caller graph for this function:

string cmn_Time::Time2YMDhms (  )  const [inline]

string cmn_Time::Time2YMD (  )  const [inline]

Definition at line 81 of file cmn_time.h.

00081 { return c_Time2YMD()    ;};

string cmn_Time::Time2hmsm (  )  const [inline]

Definition at line 82 of file cmn_time.h.

Referenced by TreeWalk::CheckDir(), and ut_Basic::~ut_Basic().

00082 { return c_Time2hmsm()   ;};

Here is the caller graph for this function:

string cmn_Time::Time2hms (  )  const [inline]

string cmn_Time::Time2hm (  )  const [inline]

Definition at line 84 of file cmn_time.h.

00084 { return c_Time2hm()     ;};

void cmn_Time::TimeToFields (  )  [private]

Definition at line 141 of file cmn_Time.cpp.

References localtime(), m_MilliTime, m_TimeFields, and NULL.

Referenced by cmn_Time(), and Refresh().

00141                             {
00142 #ifdef TGT_OS_windows
00143     // No localtime_r on Windows and localtime is not thread safe.
00144     // TODO: tm_p access locking
00145     tm* tm_p = localtime(&m_MilliTime.time);
00146 #else
00147     tm* tm_p = localtime_r(&m_MilliTime.time, &m_TimeFields);
00148 #endif
00149     if (tm_p == NULL) {
00150         m_TimeFields.tm_mday = 0;
00151         m_TimeFields.tm_year = 0;
00152         m_TimeFields.tm_mon  = 0;
00153         m_TimeFields.tm_hour = 0;
00154         m_TimeFields.tm_min  = 0;
00155         m_TimeFields.tm_sec  = 0;
00156     }
00157     else {
00158 #ifdef TGT_OS_windows
00159         m_TimeFields = *tm_p;
00160         // TODO: Should lock tm_p access up to here.
00161 #endif
00162         m_TimeFields.tm_year += 1900;
00163         m_TimeFields.tm_mon  += 1;
00164     }
00165 }

Here is the call graph for this function:

Here is the caller graph for this function:

void cmn_Time::TimeToFieldsUTC (  )  [private]

Definition at line 167 of file cmn_Time.cpp.

References m_MilliTime, m_TimeFields, and NULL.

Referenced by cmn_Time(), and operator-=().

00167                                {
00168     tm* tm_p = gmtime(&m_MilliTime.time);
00169     if (tm_p == NULL) {
00170         m_TimeFields.tm_mday = 0;
00171         m_TimeFields.tm_year = 0;
00172         m_TimeFields.tm_mon  = 0;
00173         m_TimeFields.tm_hour = 0;
00174         m_TimeFields.tm_min  = 0;
00175         m_TimeFields.tm_sec  = 0;
00176     }
00177     else {
00178         m_TimeFields = *tm_p;
00179         m_TimeFields.tm_year += 1900;
00180         m_TimeFields.tm_mon  += 1;
00181     }
00182 }

Here is the caller graph for this function:


Member Data Documentation

struct timeb cmn_Time::m_MilliTime [read, private]

struct tm cmn_Time::m_TimeFields [read, private]

char cmn_Time::m_buf[32] [mutable, private]

Definition at line 56 of file cmn_time.h.

Referenced by c_Time2hm(), c_Time2hms(), c_Time2hmsm(), c_Time2YMD(), c_Time2YMDhms(), and c_Time2YMDhmsm().

Definition at line 59 of file cmn_time.h.


The documentation for this class was generated from the following files:

Generated on Mon Feb 27 19:05:52 2012 for OPENARCHIVE by  doxygen 1.5.6