18 #ifndef _GAZEBO_COMMON_TIME_HH_
19 #define _GAZEBO_COMMON_TIME_HH_
36 #define GZ_SEC_TO_HOUR(_s) ((_s) / 3600.0)
44 class GZ_COMMON_VISIBLE
Time
81 public:
Time(
const struct timeval &_tv);
86 public:
Time(
const struct timespec &_tv);
91 public:
Time(int32_t _sec, int32_t _nsec);
96 public:
Time(
double _time);
99 public:
virtual ~
Time();
103 public:
static const Time &GetWallTime();
107 public:
static const std::string &GetWallTimeAsISOString();
110 public:
void SetToWallTime();
115 public:
void Set(int32_t _sec, int32_t _nsec);
119 public:
void Set(
double _seconds);
123 public:
double Double()
const;
127 public:
float Float()
const;
134 public: std::string FormattedString(FormatOption _start = DAYS,
135 FormatOption _end = MILLISECONDS)
const;
145 public:
static Time MSleep(
unsigned int _ms);
150 public:
static Time NSleep(
unsigned int _ns);
155 public:
Time &operator =(
const struct timeval &_tv);
160 public:
Time &operator =(
const struct timespec &_tv);
165 public:
Time &operator =(
const Time &_time);
170 public:
Time operator +(
const struct timeval &_tv)
const;
175 public:
Time operator +(
const struct timespec &_tv)
const;
180 public:
const Time &operator +=(
const struct timeval &_tv);
185 public:
const Time &operator +=(
const struct timespec &_tv);
190 public:
Time operator +(
const Time &_time)
const;
195 public:
const Time &operator +=(
const Time &_time);
200 public:
Time operator -(
const struct timeval &_tv)
const;
205 public:
const Time &operator -=(
const struct timeval &_tv);
210 public:
Time operator -(
const struct timespec &_tv)
const;
215 public:
const Time &operator -=(
const struct timespec &_tv);
220 public:
Time operator -(
const Time &_time)
const;
225 public:
const Time &operator -=(
const Time &_time);
230 public:
Time operator *(
const struct timeval &_tv)
const;
235 public:
const Time &operator *=(
const struct timeval &_tv);
240 public:
Time operator *(
const struct timespec &_tv)
const;
245 public:
const Time &operator *=(
const struct timespec &_tv);
250 public:
Time operator *(
const Time &_time)
const;
255 public:
const Time &operator *=(
const Time &_time);
260 public:
Time operator /(
const struct timeval &_tv)
const;
265 public:
const Time &operator /=(
const struct timeval &_tv);
270 public:
Time operator /(
const struct timespec &_tv)
const;
275 public:
const Time &operator /=(
const struct timespec &_tv);
280 public:
Time operator /(
const Time &_time)
const;
285 public:
const Time &operator /=(
const Time &time);
290 public:
bool operator ==(
const struct timeval &_tv)
const;
295 public:
bool operator ==(
const struct timespec &_tv)
const;
300 public:
bool operator ==(
const Time &_time)
const;
305 public:
bool operator ==(
double _time)
const;
310 public:
bool operator!=(
const struct timeval &_tv)
const;
315 public:
bool operator!=(
const struct timespec &_tv)
const;
320 public:
bool operator!=(
const Time &_time)
const;
325 public:
bool operator!=(
double _time)
const;
330 public:
bool operator<(
const struct timeval &_tv)
const;
335 public:
bool operator<(
const struct timespec &_tv)
const;
340 public:
bool operator<(
const Time &_time)
const;
345 public:
bool operator<(
double _time)
const;
350 public:
bool operator<=(
const struct timeval &_tv)
const;
355 public:
bool operator<=(
const struct timespec &_tv)
const;
360 public:
bool operator<=(
const Time &_time)
const;
365 public:
bool operator<=(
double _time)
const;
370 public:
bool operator>(
const struct timeval &_tv)
const;
375 public:
bool operator>(
const struct timespec &_tv)
const;
380 public:
bool operator>(
const Time &_time)
const;
385 public:
bool operator>(
double _time)
const;
390 public:
bool operator>=(
const struct timeval &_tv)
const;
395 public:
bool operator>=(
const struct timespec &_tv)
const;
400 public:
bool operator>=(
const Time &_time)
const;
405 public:
bool operator>=(
double _time)
const;
411 {
return _sec * 1e9;}
432 _out << _time.
sec <<
" " << _time.
nsec;
444 _in.setf(std::ios_base::skipws);
445 _in >> _time.
sec >> _time.
nsec;
463 private:
static Time wallTime;
466 private:
static std::string wallTimeISO;
470 private:
inline void Correct()
473 if (this->sec > 0 && this->nsec < 0)
475 int32_t n = abs(this->nsec / this->nsInSec) + 1;
477 this->nsec += n * this->nsInSec;
479 if (this->sec < 0 && this->nsec > 0)
481 int32_t n = abs(this->nsec / this->nsInSec) + 1;
483 this->nsec -= n * this->nsInSec;
487 this->sec += this->nsec / this->nsInSec;
488 this->nsec = this->nsec % this->nsInSec;
491 private:
static struct timespec clockResolution;
static const int32_t nsInSec
Constant multiplier to convert from nanoseconds to seconds.
Definition: Time.hh:456
int32_t nsec
Nanoseconds.
Definition: Time.hh:453
static const Time Hour
A static time variable set to an hour: common::Time(3600, 0).
Definition: Time.hh:53
int32_t sec
Seconds.
Definition: Time.hh:450
friend std::ostream & operator<<(std::ostream &_out, const gazebo::common::Time &_time)
Stream insertion operator.
Definition: Time.hh:429
static const int32_t nsInMs
Constant multiplier to convert from nanoseconds to milliseconds.
Definition: Time.hh:460
static double MilToNano(double _ms)
Convert milliseconds to nanoseconds.
Definition: Time.hh:416
FormatOption
Definition: Time.hh:57
static double MicToNano(double _ms)
Convert microseconds to nanoseconds.
Definition: Time.hh:422
GAZEBO_VISIBLE void Set(common::Image &_img, const msgs::Image &_msg)
Convert a msgs::Image to a common::Image.
static double SecToNano(double _sec)
Convert seconds to nanoseconds.
Definition: Time.hh:410
friend std::istream & operator>>(std::istream &_in, gazebo::common::Time &_time)
Stream extraction operator.
Definition: Time.hh:440
static const Time Second
A static time variable set to a second: common::Time(1, 0).
Definition: Time.hh:50
static const Time Zero
A static zero time variable set to common::Time(0, 0).
Definition: Time.hh:47
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:44