Public Member Functions | Public Attributes | Private Member Functions | Private Attributes

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

#include <cmn_time.h>

List of all members.

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
char * c_Time2HL7 () const
char * c_GetTimeStamp () const
string Time2YMDhmsm () const
string Time2YMDhms () const
string Time2YMD () const
string Time2hmsm () const
string Time2hms () const
string Time2hm () const
string Time2HL7 () const
string GetTimeStamp () 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]

Detailed Description

Definition at line 37 of file cmn_time.h.


Constructor & Destructor Documentation

cmn_Time::cmn_Time (  ) 

Definition at line 54 of file cmn_Time.cpp.

References Refresh().

Referenced by operator-().

                   {
    Refresh();
}

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 58 of file cmn_Time.cpp.

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

                                                                   {
    ivd_FTime(&m_MilliTime);        // to get proper timezone
    m_MilliTime.time    = a_time;
    m_MilliTime.millitm = a_mili;
    if (a_UTC) {
        TimeToFieldsUTC();
    }
    else {
        TimeToFields();
    }
}

Here is the call graph for this function:

cmn_Time::cmn_Time ( const string  a_time  ) 

Definition at line 71 of file cmn_Time.cpp.

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

                                      {

    log_FUNC_m(cmn_Time);

    string strDate(""); //string up to first space
    string strTime(""); //string after first spacehole

    size_t spacePos;
    spacePos = a_time.find(" ", 0);
    strDate = a_time.substr(0, spacePos);

    if (strDate.length() < a_time.length() ) {
        spacePos = a_time.find_last_of(" " ,spacePos);
        strTime = a_time.substr(spacePos+1, a_time.length());
    }

    int year = 0, month = 0 , day = 0;
    int errCode = sscanf(strDate.c_str(), "%d/%d/%d", &year, &month, &day);

    int hour = 0, min = 0 , sec = 0;
    if  (errCode == 3) {
        if  (strTime.length() > 0) {
            errCode = sscanf(strTime.c_str(), "%d:%d:%d", &hour, &min, &sec);
            if (errCode < 3) {
                throw ivd_Error(ie_NOT_VALID, "Time: wrong=" + strTime);
            }
        }
    } else {
        throw ivd_Error(ie_NOT_VALID, "Date: wrong=" + strDate);
    }

    if (year >= 1900) {
        m_TimeFields.tm_year = year - 1900;
    } else throw ivd_Error(ie_NOT_VALID, "Year: wrong=" + cmn_Num2Str(year));

    if ((month > 0) && (month <= 12)) {
        m_TimeFields.tm_mon = month - 1;
    } else throw ivd_Error(ie_NOT_VALID, "Month: wrong=" + cmn_Num2Str(month));

    if ((day > 0) && (day <= 31)) {
        m_TimeFields.tm_mday = day;
    } else throw ivd_Error(ie_NOT_VALID, "Day: wrong=" + cmn_Num2Str(day));

    if ((hour >= 0) && (hour < 24)) {
        m_TimeFields.tm_hour = hour;
    } else throw ivd_Error(ie_NOT_VALID, "Hour: wrong=" + cmn_Num2Str(hour));

    if ((min >= 0) && (min <= 59)) {
        m_TimeFields.tm_min = min;
    } else throw ivd_Error(ie_NOT_VALID, "Min: wrong=" + cmn_Num2Str(min));

    if ((sec >= 0) && (sec <= 59)) {
        m_TimeFields.tm_sec = sec;
    } else throw ivd_Error(ie_NOT_VALID, "Sec: wrong=" + cmn_Num2Str(sec));

    m_TimeFields.tm_isdst = -1;
    m_MilliTime.time = mktime( &m_TimeFields);
    m_MilliTime.millitm = 0;
}

Here is the call graph for this function:

cmn_Time::~cmn_Time (  )  [inline]

Definition at line 44 of file cmn_time.h.

{};


Member Function Documentation

char * cmn_Time::c_GetTimeStamp (  )  const

Definition at line 263 of file cmn_Time.cpp.

References m_buf, m_MilliTime, and m_TimeFields.

                                     {
    sprintf(m_buf,"%4d%02d%02d%02d%02d%02d%03d",
        m_TimeFields.tm_year,
        m_TimeFields.tm_mon,
        m_TimeFields.tm_mday,
        m_TimeFields.tm_hour,
        m_TimeFields.tm_min,
        m_TimeFields.tm_sec,
        m_MilliTime.millitm);
    return m_buf;
}

char * cmn_Time::c_Time2HL7 (  )  const

Definition at line 253 of file cmn_Time.cpp.

References m_buf, and m_TimeFields.

                                 {
    sprintf(m_buf,"%4d%02d%02d%02d%02d",
        m_TimeFields.tm_year,
        m_TimeFields.tm_mon,
        m_TimeFields.tm_mday,
        m_TimeFields.tm_hour,
        m_TimeFields.tm_min);
    return m_buf;
}

char * cmn_Time::c_Time2hm (  )  const

Definition at line 246 of file cmn_Time.cpp.

References m_buf, and m_TimeFields.

                                {
    sprintf(m_buf,"%02d:%02d",
        m_TimeFields.tm_hour,
        m_TimeFields.tm_min);
    return m_buf;
}

char * cmn_Time::c_Time2hms (  )  const

Definition at line 238 of file cmn_Time.cpp.

References m_buf, and m_TimeFields.

                                 {
    sprintf(m_buf,"%02d:%02d:%02d",
        m_TimeFields.tm_hour,
        m_TimeFields.tm_min,
        m_TimeFields.tm_sec);
    return m_buf;
}

char * cmn_Time::c_Time2hmsm (  )  const

Definition at line 229 of file cmn_Time.cpp.

References m_buf, m_MilliTime, and m_TimeFields.

Referenced by log_Debugger::WriteHeader().

                                  {
    sprintf(m_buf,"%02d:%02d:%02d.%03d",
        m_TimeFields.tm_hour,
        m_TimeFields.tm_min,
        m_TimeFields.tm_sec,
        m_MilliTime.millitm);
    return m_buf;
}

Here is the caller graph for this function:

char * cmn_Time::c_Time2YMD (  )  const

Definition at line 221 of file cmn_Time.cpp.

References m_buf, and m_TimeFields.

                                 {
    sprintf(m_buf,"%4d/%02d/%02d",
        m_TimeFields.tm_year,
        m_TimeFields.tm_mon,
        m_TimeFields.tm_mday);
    return m_buf;
}

char * cmn_Time::c_Time2YMDhms (  )  const

Definition at line 210 of file cmn_Time.cpp.

References m_buf, and m_TimeFields.

Referenced by ui_MsgWriter::DisplayMessage(), cfg_CollocationInfo::GenerateCollocationInfoFile(), cfg_HL7Info::GenerateHL7InfoFile(), i_ManagementInterface_i::ListDrives(), i_ManagementInterface_i::ListLibraries(), and i_ManagementInterface_i::ListMediumVolumes().

                                    {
    sprintf(m_buf,"%4d/%02d/%02d %02d:%02d:%02d",
        m_TimeFields.tm_year,
        m_TimeFields.tm_mon,
        m_TimeFields.tm_mday,
        m_TimeFields.tm_hour,
        m_TimeFields.tm_min,
        m_TimeFields.tm_sec);
    return m_buf;
}

Here is the caller graph for this function:

char * cmn_Time::c_Time2YMDhmsm (  )  const

Definition at line 198 of file cmn_Time.cpp.

References m_buf, m_MilliTime, and m_TimeFields.

Referenced by log_Debugger::WriteHeader().

                                     {
    sprintf(m_buf,"%4d/%02d/%02d %02d:%02d:%02d.%03d",
        m_TimeFields.tm_year,
        m_TimeFields.tm_mon,
        m_TimeFields.tm_mday,
        m_TimeFields.tm_hour,
        m_TimeFields.tm_min,
        m_TimeFields.tm_sec,
        m_MilliTime.millitm);
    return m_buf;
}

Here is the caller graph for this function:

unsigned short cmn_Time::GetMilliTime (  )  [inline]
time_t cmn_Time::GetTime_t (  )  [inline]
UInt64_t cmn_Time::GetTimeInMicroSec (  )  [inline]

Definition at line 85 of file cmn_time.h.

Referenced by TreeWalk::CheckDir().

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

Here is the caller graph for this function:

UInt64_t cmn_Time::GetTimeInMiliSec (  )  [inline]

Definition at line 83 of file cmn_time.h.

Referenced by Rate().

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

Here is the caller graph for this function:

string cmn_Time::GetTimeStamp (  )  const [inline]

Definition at line 102 of file cmn_time.h.

Referenced by hsm_HL7CacheFile::HandleCoruptedFile().

{ return c_GetTimeStamp();};

Here is the caller graph for this function:

cmn_Time cmn_Time::operator- ( const cmn_Time t1  ) 

Definition at line 131 of file cmn_Time.cpp.

References cmn_Time().

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

Here is the call graph for this function:

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

Definition at line 135 of file cmn_Time.cpp.

References m_MilliTime, and TimeToFieldsUTC().

                                                   {

    if (m_MilliTime.millitm < t1.m_MilliTime.millitm) {
        m_MilliTime.millitm += (1000 - t1.m_MilliTime.millitm);
        m_MilliTime.time    -= (t1.m_MilliTime.time + 1);
    }
    else {
        m_MilliTime.millitm -= t1.m_MilliTime.millitm;
        m_MilliTime.time    -= t1.m_MilliTime.time;
    }

    TimeToFieldsUTC();  // relative time is need. don't use location
    return *this;
}

Here is the call graph for this function:

void cmn_Time::Refresh (  ) 

Definition at line 150 of file cmn_Time.cpp.

References ivd_FTime, m_MilliTime, and TimeToFields().

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

Here is the call graph for this function:

Here is the caller graph for this function:

string cmn_Time::Time2HL7 (  )  const [inline]

Definition at line 101 of file cmn_time.h.

Referenced by hl7::CreateHL7Message().

{ return c_Time2HL7()    ;};

Here is the caller graph for this function:

string cmn_Time::Time2hm (  )  const [inline]

Definition at line 100 of file cmn_time.h.

{ return c_Time2hm()     ;};

string cmn_Time::Time2hms (  )  const [inline]
string cmn_Time::Time2hmsm (  )  const [inline]

Definition at line 98 of file cmn_time.h.

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

{ return c_Time2hmsm()   ;};

Here is the caller graph for this function:

string cmn_Time::Time2YMD (  )  const [inline]

Definition at line 97 of file cmn_time.h.

{ return c_Time2YMD()    ;};

string cmn_Time::Time2YMDhms (  )  const [inline]
string cmn_Time::Time2YMDhmsm (  )  const [inline]

Definition at line 95 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().

{ return c_Time2YMDhmsm();};

Here is the caller graph for this function:

void cmn_Time::TimeToFields (  )  [private]

Definition at line 155 of file cmn_Time.cpp.

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

Referenced by cmn_Time(), and Refresh().

                            {
#ifdef TGT_OS_windows
    // No localtime_r on Windows and localtime is not thread safe.
    // TODO: tm_p access locking
    tm* tm_p = localtime(&m_MilliTime.time);
#else
    tm* tm_p = localtime_r(&m_MilliTime.time, &m_TimeFields);
#endif
    if (tm_p == NULL) {
        m_TimeFields.tm_mday = 0;
        m_TimeFields.tm_year = 0;
        m_TimeFields.tm_mon  = 0;
        m_TimeFields.tm_hour = 0;
        m_TimeFields.tm_min  = 0;
        m_TimeFields.tm_sec  = 0;
    }
    else {
#ifdef TGT_OS_windows
        m_TimeFields = *tm_p;
        // TODO: Should lock tm_p access up to here.
#endif
        m_TimeFields.tm_year += 1900;
        m_TimeFields.tm_mon  += 1;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void cmn_Time::TimeToFieldsUTC (  )  [private]

Definition at line 181 of file cmn_Time.cpp.

References m_MilliTime, m_TimeFields, and NULL.

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

                               {
    tm* tm_p = gmtime(&m_MilliTime.time);
    if (tm_p == NULL) {
        m_TimeFields.tm_mday = 0;
        m_TimeFields.tm_year = 0;
        m_TimeFields.tm_mon  = 0;
        m_TimeFields.tm_hour = 0;
        m_TimeFields.tm_min  = 0;
        m_TimeFields.tm_sec  = 0;
    }
    else {
        m_TimeFields = *tm_p;
        m_TimeFields.tm_year += 1900;
        m_TimeFields.tm_mon  += 1;
    }
}

Here is the caller graph for this function:


Member Data Documentation

Definition at line 73 of file cmn_time.h.

char cmn_Time::m_buf[32] [mutable, private]
struct timeb cmn_Time::m_MilliTime [private]
struct tm cmn_Time::m_TimeFields [private]

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