EpcTools
An event based multi-threaded C++ development framework.
|
Go to the documentation of this file.
18 #ifndef __etime_h_included
19 #define __etime_h_included
38 #define MON_DAY_YEAR_ORDER 1
39 #define YEAR_MON_DAY_ORDER 2
40 #define YEAR_DAY_MON_ORDER 4
41 #define DAY_MON_YEAR_ORDER 8
42 #define MON_YEAR_DAY_ORDER 16
45 #define SWAP_POSITION(a, b) \
52 #define GIVE_YEAR(year) \
55 year = year < 30 ? 2000 + year : year < 100 ? 1900 + year : year; \
58 #define stringcmp_format(string1, string2, count) __builtin_strncasecmp(string1, string2, count)
59 #define format_localtime_s(a, b) localtime_r(b, a)
60 #define format_gmtime_s(a, b) gmtime_r(b, a)
61 #define format_sprintf_s __builtin_snprintf
63 #define BASE_YEAR 1900
64 #define NUM_OF_DAYS_LEAPYEAR 366
65 #define NUM_OF_DAYS_YEAR 365
66 #define NUM_OF_DAYS_WEEK 7
68 #define IF_LEAPYEAR(year) (!((year) % 4) && (((year) % 100) || !((year) % 400)))
70 #define FORMAT_TIMEZONE timezone
72 #define FORMAT_DAYLIGHT daylight
75 cpStr type_format,
const struct tm *time_f,
const struct timeval *tval);
77 pStr
format_time_into_specs(cpStr format,
const struct tm *t, pStr pt, cpStr ptlim,
const struct timeval *tv);
84 NAME_DAY_WEEK_ABB =
'a',
92 DAY_AS_DECIMAL_0 =
'e',
97 ABBRE_MON_NAME_2 =
'h',
100 DAY_AS_DECIMAL =
'j',
101 HOUR_AS_24_SINGLE =
'k',
102 HOUR_AS_12_SINGLE =
'l',
103 MON_AS_DECIMAL =
'm',
104 MIN_AS_DECIMAL =
'M',
112 SECONDS_AS_DEC =
'S',
114 TIME_IN_24_HOUR =
'T',
115 DAY_WEEK_AS_DEC =
'u',
116 WEEK_NUM_AS_DEC =
'U',
119 WEEK_NUM_AS_DEC_MON =
'W',
120 DATE_WITHOUT_TIME =
'x',
121 TIME_WITHOUT_DATE =
'X',
122 YEAR_WITHOUT_CEN =
'y',
124 HOUR_MIN_OFFSET =
'z',
137 UInt field_flags[DATE_FIELDS];
138 UInt field_parse_flags;
139 UInt field_values[DATE_FIELDS];
220 m_time.tv_usec = usec;
238 ETime(Int
year, Int mon, Int
day, Int
hour, Int min, Int sec, Bool isLocal);
250 m_time.tv_sec = a.m_time.tv_sec;
251 m_time.tv_usec = a.m_time.tv_usec;
277 return ((m_time.tv_sec == a.m_time.tv_sec) && (m_time.tv_usec == a.m_time.tv_usec));
285 return ((m_time.tv_sec != a.m_time.tv_sec) || (m_time.tv_usec != a.m_time.tv_usec));
293 if (m_time.tv_sec < a.m_time.tv_sec)
295 if (m_time.tv_sec == a.m_time.tv_sec)
297 if (m_time.tv_usec < a.m_time.tv_usec)
309 if (m_time.tv_sec > a.m_time.tv_sec)
311 if (m_time.tv_sec == a.m_time.tv_sec)
313 if (m_time.tv_usec > a.m_time.tv_usec)
341 return add(a.m_time);
375 ETime add(Int days, Int hrs, Int mins, Int secs, Int usecs)
395 nt.m_time.tv_sec += t.tv_sec;
396 nt.m_time.tv_usec += t.tv_usec;
397 if (nt.m_time.tv_usec >= 1000000)
399 nt.m_time.tv_usec -= 1000000;
433 nt.m_time.tv_sec -= t.tv_sec;
434 nt.m_time.tv_usec -= t.tv_usec;
435 if (nt.m_time.tv_usec < 0)
437 nt.m_time.tv_usec += 1000000;
456 m_time.tv_sec = a.tv_sec;
457 m_time.tv_usec = a.tv_usec;
466 m_time.tv_sec = ms / 1000;
467 m_time.tv_usec = (ms % 1000) * 1000;
475 return m_time.tv_sec * 1000 + (m_time.tv_usec / 1000);
487 Bool
isValid() {
return m_time.tv_sec != 0 || m_time.tv_usec != 0; }
521 Void
Format(pStr dest, Int maxsize, cpStr fmt, Bool local);
537 #endif // #define __etime_h_included
Void setNTPTime(const ntp_time_t &ntp)
Assigns the time represented by the NTP time to this ETime object.
Definition: etime.cpp:1188
ETime & operator=(const ETime &a)
Assignment operator.
Definition: etime.h:248
ETime operator+(const timeval &t)
Addition operator.
Definition: etime.h:347
pStr format_time_into_specs(cpStr time_format, const struct tm *t, pStr dest, cpStr max_limit, const struct timeval *p_timeval)
Definition: etime.cpp:141
ETime operator+(const ETime &a)
Addition operator.
Definition: etime.h:339
Class for manipulating date and time of day values.
Definition: etime.h:199
static ETime Now()
Retrieves the current time.
Definition: etime.cpp:1147
~ETime()
Class destructor.
Definition: etime.h:241
Int second()
Retrieves the second.
Definition: etime.cpp:1139
#define True
True.
Definition: ebase.h:25
ETime subtract(const timeval &t)
Subtracts the timeval amount to the current value.
Definition: etime.h:429
ETime & operator=(LongLong ms)
Assignment operator.
Definition: etime.h:266
Macros for various standard C library functions and standard includes.
ETime & set(LongLong ms)
Assigns the specified millisecond value to this ETime object.
Definition: etime.h:464
ETime operator-(const timeval &t)
Subtraction operator.
Definition: etime.h:363
Bool operator==(const ETime &a)
Equality operator.
Definition: etime.h:275
Bool operator>=(const ETime &a)
Greater than or equal to operator.
Definition: etime.h:323
size_t format_time_into_string(pStr st, size_t max_limit, cpStr type_format, struct tm *time_f, const struct timeval *tval)
Definition: etime.cpp:119
Int day()
Retrieves the day.
Definition: etime.cpp:1115
ETime(Int sec, Int usec)
Class constructor.
Definition: etime.h:217
Bool operator<(const ETime &a)
Less than operator.
Definition: etime.h:291
Int month()
Retrieves the month.
Definition: etime.cpp:1107
ETime add(const timeval &t)
Adds the timeval amount to the current value.
Definition: etime.h:391
const timeval & getTimeVal()
Retrieves a reference to the timeval structure.
Definition: etime.h:446
Bool ParseDateTime(cpStr pszDate, Bool isLocal=True)
Parses the string containing the time and date.
Definition: etime.cpp:1177
pStr convert_date_time_format(const Int n, cpStr date_time_format, pStr dest_buffer, cpStr max_dest_limit)
Definition: etime.cpp:461
EString Format(cpStr fmt, Bool local)
Formats the date/time value as specified by the format string.
Definition: etime.h:526
ETime(LongLong ms)
Class constructor.
Definition: etime.h:225
Void Format(EString &dest, cpStr fmt, Bool local)
Formats the date/time value as specified by the format string.
Definition: etime.cpp:1157
Bool isValid()
Indicates whether this ETime object is valid or not.
Definition: etime.h:487
ETime subtract(Int days, Int hrs, Int mins, Int secs, Int usecs)
Subtracts the specified days, hours minutes seconds and microseconds to the current value.
Definition: etime.h:413
Int minute()
Retrieves the minute.
Definition: etime.cpp:1131
Int hour()
Retrieves the hour.
Definition: etime.cpp:1123
LongLong getCassandraTimestmap()
Converts this ETime value to one compatible with a Cassandra timestamp.
Definition: etime.h:473
ETime operator-(const ETime &a)
Subtraction operator.
Definition: etime.h:355
ETime()
Default constructor. Initializes to current time.
Definition: etime.h:203
Bool operator!=(const ETime &a)
Inequality operator.
Definition: etime.h:283
String class.
Definition: estring.h:30
ETime(const ETime &a)
Copy constructor.
Definition: etime.h:209
ETime & set(const timeval &a)
Assigns the specified timeval value to this ETime object.
Definition: etime.h:454
ETime & operator=(const timeval &a)
Assignment operator.
Definition: etime.h:258
Bool operator>(const ETime &a)
Greater than operator.
Definition: etime.h:307
Int year()
Retrieves the year.
Definition: etime.cpp:1099
Bool operator<=(const ETime &a)
Less than or equal to operator.
Definition: etime.h:331
Encapsulates and extends a std::string object.
Void getNTPTime(ntp_time_t &ntp) const
Retrieves the NTP time representation of this ETime object.
Definition: etime.cpp:1182
ETime add(Int days, Int hrs, Int mins, Int secs, Int usecs)
Adds the specified days, hours minutes seconds and microseconds to the current value.
Definition: etime.h:375
pStr add_timeformat_to_string(cpStr buffer, pStr dest_buffer, cpStr max_dest_limit)
Definition: etime.cpp:470