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);
357 return subtract(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);
480 Void getNTPTime(ntp_time_t &ntp)
const;
483 Void setNTPTime(
const ntp_time_t &ntp);
491 t.fraction = fraction;
500 Bool
isValid() {
return m_time.tv_sec != 0 || m_time.tv_usec != 0; }
528 Void Format(
EString &dest, cpStr fmt, Bool local)
const;
534 Void Format(pStr dest, Int maxsize, cpStr fmt, Bool local)
const;
544 Bool ParseDateTime(cpStr pszDate, Bool isLocal =
True);
550 #endif // #define __etime_h_included ETime & operator=(const ETime &a)
Assignment operator.
Definition: etime.h:248
pStr add_timeformat_to_string(cpStr buffer, pStr dest_buffer, cpStr max_dest_limit)
Definition: etime.cpp:470
Encapsulates and extends a std::string object.
#define True
True.
Definition: ebase.h:25
EString Format(cpStr fmt, Bool local) const
Formats the date/time value as specified by the format string.
Definition: etime.h:539
Macros for various standard C library functions and standard includes.
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=(LongLong ms)
Assignment operator.
Definition: etime.h:266
Bool operator<(const ETime &a) const
Less than operator.
Definition: etime.h:291
ETime operator+(const ETime &a)
Addition operator.
Definition: etime.h:339
ETime subtract(Int days, Int hrs, Int mins, Int secs, Int usecs) const
Subtracts the specified days, hours minutes seconds and microseconds to the current value...
Definition: etime.h:413
ETime operator+(const timeval &t)
Addition operator.
Definition: etime.h:347
ETime operator-(const timeval &t) const
Subtraction operator.
Definition: etime.h:363
Bool operator>=(const ETime &a) const
Greater than or equal to operator.
Definition: etime.h:323
~ETime()
Class destructor.
Definition: etime.h:241
ETime subtract(const timeval &t) const
Subtracts the timeval amount to the current value.
Definition: etime.h:429
ETime add(const timeval &t)
Adds the timeval amount to the current value.
Definition: etime.h:391
Bool operator==(const ETime &a) const
Equality operator.
Definition: etime.h:275
Class for manipulating date and time of day values.
Definition: etime.h:199
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
ETime(LongLong ms)
Class constructor.
Definition: etime.h:225
ETime operator-(const ETime &a) const
Subtraction operator.
Definition: etime.h:355
Bool operator<=(const ETime &a) const
Less than or equal to operator.
Definition: etime.h:331
ETime(Int sec, Int usec)
Class constructor.
Definition: etime.h:217
Bool operator!=(const ETime &a) const
Inequality operator.
Definition: etime.h:283
Void setNTPTime(const UInt seconds, const UInt fraction=0)
Assigns the time represented by the NTP time seconds (only) to this ETime object. ...
Definition: etime.h:487
ETime()
Default constructor. Initializes to current time.
Definition: etime.h:203
pStr convert_date_time_format(const Int n, cpStr date_time_format, pStr dest_buffer, cpStr max_dest_limit)
Definition: etime.cpp:461
ETime & operator=(const timeval &a)
Assignment operator.
Definition: etime.h:258
Bool isValid()
Indicates whether this ETime object is valid or not.
Definition: etime.h:500
UInt getNTPTimeSeconds() const
Retrieves the NTP time seconds representation of this ETime object.
Definition: etime.h:496
ETime(const ETime &a)
Copy constructor.
Definition: etime.h:209
const timeval & getTimeVal() const
Retrieves a reference to the timeval structure.
Definition: etime.h:446
LongLong getCassandraTimestmap()
Converts this ETime value to one compatible with a Cassandra timestamp.
Definition: etime.h:473
String class.
Definition: estring.h:31
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
Bool operator>(const ETime &a) const
Greater than operator.
Definition: etime.h:307