18#ifndef _GAZEBO_COMMON_TIME_HH_
19#define _GAZEBO_COMMON_TIME_HH_
39 #define GZ_SEC_TO_HOUR(_s) ((_s) / 3600.0)
47 class GZ_COMMON_VISIBLE
Time
84 public:
Time(
const struct timeval &_tv);
89 public:
Time(
const struct timespec &_tv);
94 public:
Time(int32_t _sec, int32_t _nsec);
99 public:
Time(
double _time);
124 public:
void Set(int32_t _sec, int32_t _nsec);
128 public:
void Set(
double _seconds);
164 public:
Time &operator =(
const struct timeval &_tv);
169 public:
Time &operator =(
const struct timespec &_tv);
179 public:
Time operator +(
const struct timeval &_tv)
const;
184 public:
Time operator +(
const struct timespec &_tv)
const;
189 public:
const Time &operator +=(
const struct timeval &_tv);
194 public:
const Time &operator +=(
const struct timespec &_tv);
204 public:
const Time &operator +=(
const Time &_time);
209 public:
Time operator -(
const struct timeval &_tv)
const;
214 public:
const Time &operator -=(
const struct timeval &_tv);
219 public:
Time operator -(
const struct timespec &_tv)
const;
224 public:
const Time &operator -=(
const struct timespec &_tv);
234 public:
const Time &operator -=(
const Time &_time);
239 public:
Time operator *(
const struct timeval &_tv)
const;
244 public:
const Time &operator *=(
const struct timeval &_tv);
249 public:
Time operator *(
const struct timespec &_tv)
const;
254 public:
const Time &operator *=(
const struct timespec &_tv);
264 public:
const Time &operator *=(
const Time &_time);
269 public:
Time operator /(
const struct timeval &_tv)
const;
274 public:
const Time &operator /=(
const struct timeval &_tv);
279 public:
Time operator /(
const struct timespec &_tv)
const;
284 public:
const Time &operator /=(
const struct timespec &_tv);
299 public:
bool operator ==(
const struct timeval &_tv)
const;
304 public:
bool operator ==(
const struct timespec &_tv)
const;
309 public:
bool operator ==(
const Time &_time)
const;
314 public:
bool operator ==(
double _time)
const;
339 public:
bool operator<(
const struct timeval &_tv)
const;
344 public:
bool operator<(
const struct timespec &_tv)
const;
379 public:
bool operator>(
const struct timeval &_tv)
const;
384 public:
bool operator>(
const struct timespec &_tv)
const;
420 {
return _sec * 1e9;}
441 _out << _time.
sec <<
" " << _time.
nsec;
453 _in.setf(std::ios_base::skipws);
454 _in >> _time.
sec >> _time.
nsec;
472 private:
static Time wallTime;
475 private:
static std::string wallTimeISO;
479 private:
inline void Correct()
482 if (this->sec > 0 && this->nsec < 0)
484 int32_t n = abs(this->nsec / this->nsInSec) + 1;
486 this->nsec += n * this->nsInSec;
488 if (this->sec < 0 && this->nsec > 0)
490 int32_t n = abs(this->nsec / this->nsInSec) + 1;
492 this->nsec -= n * this->nsInSec;
496 this->sec += this->nsec / this->nsInSec;
497 this->nsec = this->nsec % this->nsInSec;
500 private:
static struct timespec clockResolution;
common
Definition FuelModelDatabase.hh:37
A Time class, can be used to hold wall- or sim-time.
Definition Time.hh:48
Time operator*(const struct timeval &_tv) const
Multiplication operator.
Time(int32_t _sec, int32_t _nsec)
Constructor.
bool operator>=(const struct timespec &_tv) const
Greater than or equal operator.
static Time Maximum()
Get a Time object that represents the maximum amount of time that this class can represent.
const Time & operator-=(const struct timeval &_tv)
Subtraction assignment operator.
Time(const struct timeval &_tv)
Constructor.
bool operator==(const struct timeval &_tv) const
Equal to operator.
static Time Sleep(const common::Time &_time)
Sleep for the specified time.
bool operator>(const struct timespec &_tv) const
Greater than operator.
bool operator<(double _time) const
Less than operator.
const Time & operator/=(const struct timeval &_tv)
Division assignment operator.
bool operator<(const Time &_time) const
Less than operator.
const Time & operator*=(const struct timeval &_tv)
Multiplication assignment operator.
bool operator!=(const struct timespec &_tv) const
Equal to operator.
double Double() const
Get the time as a double.
bool operator<(const struct timeval &_tv) const
Less than operator.
Time operator+(const struct timeval &_tv) const
Addition operators.
static const int32_t nsInSec
Constant multiplier to convert from nanoseconds to seconds.
Definition Time.hh:465
int32_t nsec
Nanoseconds.
Definition Time.hh:462
static double MilToNano(double _ms)
Convert milliseconds to nanoseconds.
Definition Time.hh:425
friend std::istream & operator>>(std::istream &_in, gazebo::common::Time &_time)
Stream extraction operator.
Definition Time.hh:449
static const int32_t nsInMs
Constant multiplier to convert from nanoseconds to milliseconds.
Definition Time.hh:469
bool operator>(const Time &_time) const
Greater than operator.
friend std::ostream & operator<<(std::ostream &_out, const gazebo::common::Time &_time)
Stream insertion operator.
Definition Time.hh:438
bool operator<=(const struct timespec &_tv) const
Less than or equal to operator.
static Time MSleep(unsigned int _ms)
Millisecond sleep.
bool operator>=(double _time) const
Greater than or equal operator.
std::string FormattedString(FormatOption _start=DAYS, FormatOption _end=MILLISECONDS) const
Get the time as a string formatted as "DD hh:mm:ss.mmm", with the option to choose the start/end.
void SetToWallTime()
Set the time to the wall time.
bool operator!=(const struct timeval &_tv) const
Equal to operator.
virtual ~Time()
Destructor.
bool operator<=(const Time &_time) const
Less than or equal to operator.
static const std::string & GetWallTimeAsISOString()
Get the wall time as an ISO string: YYYY-MM-DDTHH:MM:SS.
Time(double _time)
Constuctor.
static Time NSleep(unsigned int _ns)
Nano sleep.
bool operator<=(double _time) const
Less than or equal to operator.
static double SecToNano(double _sec)
Convert seconds to nanoseconds.
Definition Time.hh:419
Time operator/(const struct timeval &_tv) const
Division operator.
bool operator<(const struct timespec &_tv) const
Less than operator.
float Float() const
Get the time as a float.
FormatOption
Definition Time.hh:61
@ MILLISECONDS
Milliseconds.
Definition Time.hh:71
@ MINUTES
Minutes.
Definition Time.hh:67
@ HOURS
Hours.
Definition Time.hh:65
@ SECONDS
Seconds.
Definition Time.hh:69
@ DAYS
Days.
Definition Time.hh:63
bool operator!=(double _time) const
Equal to operator.
Time operator-(const struct timeval &_tv) const
Subtraction operator.
const Time & operator+=(const struct timeval &_tv)
Addition assignment operator.
bool operator>=(const Time &_time) const
Greater than or equal operator.
int32_t sec
Seconds.
Definition Time.hh:459
static const Time Zero
A static zero time variable set to common::Time(0, 0).
Definition Time.hh:50
static const Time Second
A static time variable set to a second: common::Time(1, 0).
Definition Time.hh:53
bool operator>(const struct timeval &_tv) const
Greater than operator.
static const Time Hour
A static time variable set to an hour: common::Time(3600, 0).
Definition Time.hh:56
bool operator>=(const struct timeval &_tv) const
Greater than or equal operator.
void Set(double _seconds)
Set to seconds.
Time & operator=(const struct timeval &_tv)
Assignment operator.
void Set(int32_t _sec, int32_t _nsec)
Set to sec and nsec.
bool operator!=(const Time &_time) const
Equal to operator.
static const Time & GetWallTime()
Get the wall time.
bool operator>(double _time) const
Greater than operator.
Time(const struct timespec &_tv)
Constructor.
Time(const Time &_time)
Copy constructor.
static double MicToNano(double _ms)
Convert microseconds to nanoseconds.
Definition Time.hh:431
bool operator<=(const struct timeval &_tv) const
Less than or equal to operator.
Forward declarations for the common classes.
Definition Animation.hh:27