35 Time_Clock(
int nYear,
int nMonth,
int nDay,
int nHour,
int nMin,
int nSec,
unsigned long microseconds = 0,
int nDST = -1);
42 struct tm*
GetGmtTm(
struct tm* ptm = NULL)
const;
43 struct tm*
GetLocalTm(
struct tm* ptm = NULL)
const;
54 void Set(
int nYear,
int nMonth,
int nDay,
int nHour,
int nMin,
int nSec,
unsigned long microseconds = 0,
int nDST = -1);
71 return _my_time.tv_sec;
73 unsigned long GetUsecPart()
75 return _my_time.tv_usec;
79 std::string
Format(
const char * pFormat)
const;
80 std::string
FormatGmt(
const char * pFormat)
const;
81 const timeval & GetTval()
85 const timeval & GetTval()
const 90 struct timeval _my_time;
106 inline Time_Clock::Time_Clock(
int nYear,
int nMonth,
int nDay,
int nHour,
int nMin,
int nSec,
unsigned long microseconds ,
int nDST)
112 assert(nDay >= 1 && nDay <= 31);
114 assert(nMonth >= 1 && nMonth <= 12);
115 atm.tm_mon = nMonth - 1;
116 assert(nYear >= 1900);
117 atm.tm_year = nYear - 1900;
119 _my_time.tv_sec = (long)mktime(&atm);
120 assert(_my_time.tv_sec != -1);
121 _my_time.tv_usec = microseconds;
122 assert(_my_time.tv_usec < 1000000);
137 inline void Time_Clock::Set(
int nYear,
int nMonth,
int nDay,
int nHour,
int nMin,
int nSec,
unsigned long microseconds ,
int nDST)
143 assert(nDay >= 1 && nDay <= 31);
145 assert(nMonth >= 1 && nMonth <= 12);
146 atm.tm_mon = nMonth - 1;
147 assert(nYear >= 1900);
148 atm.tm_year = nYear - 1900;
150 _my_time.tv_sec = (long)mktime(&atm);
151 assert(_my_time.tv_sec != -1);
152 _my_time.tv_usec = microseconds;
153 assert(_my_time.tv_usec < 1000000);
171 gettimeofday(&_my_time, NULL);
181 gettimeofday(&_my_time, NULL);
195 *ptm = *gmtime((
const time_t *)&_my_time.tv_sec);
198 return gmtime((
const time_t *)&_my_time.tv_sec);
212 struct tm* ptmTemp = localtime((
const time_t *)&_my_time.tv_sec);
218 return localtime((
const time_t *)&_my_time.tv_sec);
222 #define maxTimeBufferSize 4096 234 char szBuffer[maxTimeBufferSize];
236 char * pch = szBuffer;
238 while ((ch = *pFormat++) !=
'\0')
240 assert(pch < &szBuffer[maxTimeBufferSize]);
243 switch (ch1 = *pFormat++)
250 pch += sprintf(pch,
"%03ld", (
long)(_my_time.tv_usec / 1000));
262 char szBuffer1[maxTimeBufferSize];
264 struct tm* ptmTemp = localtime((
const time_t *)&_my_time.tv_sec);
265 if (ptmTemp == NULL ||
266 !strftime(szBuffer1,
sizeof(szBuffer1), szBuffer, ptmTemp))
268 return std::string(szBuffer1);
282 char szBuffer[maxTimeBufferSize];
284 char * pch = szBuffer;
286 while ((ch = *pFormat++) !=
'\0')
288 assert(pch < &szBuffer[maxTimeBufferSize]);
291 switch (ch1 = *pFormat++)
298 pch += sprintf(pch,
"%03ld", (
long)(_my_time.tv_usec / 1000));
309 char szBuffer1[maxTimeBufferSize];
311 struct tm* ptmTemp = gmtime((
const time_t *)&_my_time.tv_sec);
312 if (ptmTemp == NULL ||
313 !strftime(szBuffer1,
sizeof(szBuffer1), szBuffer, ptmTemp))
315 return std::string(szBuffer1);
325 _my_time.tv_sec = (long)time;
326 _my_time.tv_usec = 0;
337 _my_time.tv_sec = secs;
338 _my_time.tv_usec = usecs;
339 NormalizeTime(_my_time);
349 _my_time.tv_sec = timeSrc._my_time.tv_sec;
350 _my_time.tv_usec = timeSrc._my_time.tv_usec;
360 return ((_my_time.tv_sec == time._my_time.tv_sec) && (_my_time.tv_usec == time._my_time.tv_usec));
370 return ((_my_time.tv_sec != time._my_time.tv_sec) || (_my_time.tv_usec != time._my_time.tv_usec));
381 return ((_my_time.tv_sec < time._my_time.tv_sec) ||
382 ((_my_time.tv_sec == time._my_time.tv_sec) && (_my_time.tv_usec < time._my_time.tv_usec)));
392 return ((_my_time.tv_sec > time._my_time.tv_sec) ||
393 ((_my_time.tv_sec == time._my_time.tv_sec) && (_my_time.tv_usec > time._my_time.tv_usec)));
403 return ((_my_time.tv_sec < time._my_time.tv_sec) ||
404 ((_my_time.tv_sec == time._my_time.tv_sec) && (_my_time.tv_usec <= time._my_time.tv_usec)));
414 return ((_my_time.tv_sec > time._my_time.tv_sec) ||
415 ((_my_time.tv_sec == time._my_time.tv_sec) && (_my_time.tv_usec >= time._my_time.tv_usec)));
425 if (&timeSrc ==
this)
428 _my_time = timeSrc._my_time;
439 _my_time.tv_sec = (long)t;
440 _my_time.tv_usec = 0;
450 return _my_time.tv_sec;
std::string Format(const char *pFormat) const
Used to allow access to the "C" library strftime functions.
int GetDay() const
Return type : inline int.
const Time_Clock & operator+=(const Time_Span &Time_Span)
Return type : inline const Argument : Time_Span &Time_Span.
int GetMinute() const
Return type : inline int.
int GetDayOfWeek() const
Return type : inline int.
bool operator<=(const Time_Clock &time) const
Return type : inline bool Argument : const Time_Clock &time.
bool operator==(const Time_Clock &time) const
bool operator!=(const Time_Clock &time) const
.is time != Return type : inline bool Argument : const Time_Clock &time
time_t GetTime() const
Return type : inline time_t.
std::string FormatGmt(const char *pFormat) const
A Wraper to.
struct tm * GetLocalTm(struct tm *ptm=NULL) const
Gets The local time in a tm structre from the internal time value.
bool operator>=(const Time_Clock &time) const
Return type : inline bool Argument : const Time_Clock &time.
int GetHour() const
Return type : inline int.
int GetSecond() const
Return type : inline int.
void ToCurrentTime()
Load this object with the current OS time Return type : inline void Argument : void.
bool operator<(const Time_Clock &time) const
Return type : inline bool Argument : const Time_Clock &time.
struct tm * GetGmtTm(struct tm *ptm=NULL) const
Access the stored time and convers to a struct tm format If storage location is specified then it wil...
const Time_Clock & operator-=(const Time_Span &Time_Span)
Return type : inline const Argument : Time_Span &Time_Span.
bool operator>(const Time_Clock &time) const
Return type : inline bool Argument : const Time_Clock &time.
int GetMonth() const
Return type : inline int.
const Time_Clock & operator=(const Time_Clock &timeSrc)
Return type : inline const Argument : const Time_Clock& timeSrc.
Time_Clock()
Return type : inline.
int GetYear() const
Return type : inline int.
void Set(int nYear, int nMonth, int nDay, int nHour, int nMin, int nSec, unsigned long microseconds=0, int nDST=-1)
Return type : inline Argument : int nYear Argument : int nMonth Argument : int nDay Argument : int nH...
static Time_Clock GetCurrentTime()
The Default no param constructor.