12 #ifndef ECL_TIME_TIMESTAMP_BASE_HPP_
13 #define ECL_TIME_TIMESTAMP_BASE_HPP_
45 explicit TimeStampBase() {};
56 explicit TimeStampBase (
const double& decimal_time_value);
66 TimeStampBase (
const time_t &seconds,
const long &nanoseconds);
68 virtual ~TimeStampBase() {}
83 const TimeStampBase& stamp (
const double& decimal_time_value);
94 const TimeStampBase& stamp (
const time_t &seconds,
const long &nanoseconds);
105 long sec()
const {
return time.tv_sec; }
112 long msec()
const {
return time.tv_nsec/1000000L; }
119 long usec()
const {
return time.tv_nsec/1000; }
126 long nsec()
const {
return time.tv_nsec; }
134 operator double()
const {
return ( time.tv_sec + time.tv_nsec*0.000000001); }
144 bool operator==(
const TimeStampBase& time_stamp);
150 bool operator!=(
const TimeStampBase& time_stamp);
156 bool operator<=(
const TimeStampBase& time_stamp);
162 bool operator>=(
const TimeStampBase& time_stamp);
168 bool operator<(
const TimeStampBase& time_stamp);
174 bool operator>(
const TimeStampBase& time_stamp);
184 TimeStampBase operator+(
const TimeStampBase& time_stamp );
189 void operator+=(
const TimeStampBase& time_stamp);
199 TimeStampBase operator-(
const TimeStampBase& time_stamp );
208 void operator-=(
const TimeStampBase& time_stamp);
213 template <
typename OutputStream>
214 friend OutputStream&
operator << ( OutputStream &ostream ,
const TimeStampBase& time_stamp );
225 template <
typename OutputStream>
226 OutputStream&
operator <<( OutputStream &ostream ,
const TimeStampBase& time_stamp )
228 if ( ( time_stamp.time.tv_sec == 0 ) && (time_stamp.time.tv_nsec < 0 ) ) {
231 ostream << time_stamp.time.tv_sec <<
".";
232 long nanoseconds = std::abs(time_stamp.time.tv_nsec);
233 if ( nanoseconds < 10 ) {
234 ostream <<
"00000000";
235 }
else if ( nanoseconds < 100 ) {
236 ostream <<
"0000000";
237 }
else if ( nanoseconds < 1000 ) {
239 }
else if ( nanoseconds < 10000 ) {
241 }
else if ( nanoseconds < 100000 ) {
243 }
else if ( nanoseconds < 1000000 ) {
245 }
else if ( nanoseconds < 10000000 ) {
247 }
else if ( nanoseconds < 100000000 ) {
250 ostream << nanoseconds;