17 #ifndef IGNITION_COMMON_TIME_HH_
18 #define IGNITION_COMMON_TIME_HH_
23 #include <gz/common/config.hh>
24 #include <gz/common/Export.hh>
34 class IGNITION_COMMON_VISIBLE
Time
56 public: IGN_DEPRECATED(4)
Time();
60 public: IGN_DEPRECATED(4)
Time(const
Time &_time);
64 public: explicit IGN_DEPRECATED(4)
Time(const struct timespec &_tv);
69 public: IGN_DEPRECATED(4)
Time(int32_t _sec, int32_t _nsec);
73 public: explicit IGN_DEPRECATED(4)
Time(
double _time);
80 public: static const IGN_DEPRECATED(4)
Time &SystemTime();
85 public:
void Set(int32_t _sec, int32_t _nsec);
89 public:
void Set(
double _seconds);
93 public:
double Double() const;
97 public:
float Float() const;
107 public: static
Time IGN_DEPRECATED(4) Sleep(const common::
Time &_time);
114 public:
std::
string FormattedString(
131 public: const
Time &operator +=(const
Time &_time);
136 public:
Time operator -(const struct timespec &_tv) const;
141 public: const
Time &operator -=(const struct timespec &_tv);
151 public: const
Time &operator -=(const
Time &_time);
156 public:
Time operator *(const struct timespec &_tv) const;
161 public: const
Time &operator *=(const struct timespec &_tv);
171 public: const
Time &operator *=(const
Time &_time);
176 public: const
Time &operator /=(const struct timespec &_tv);
191 public:
bool operator==(const
Time &_time) const;
196 public:
bool operator==(
double _time) const;
201 public:
bool operator!=(const
Time &_time) const;
206 public:
bool operator!=(
double _time) const;
211 public:
bool operator<(const
Time &_time) const;
216 public:
bool operator<(
double _time) const;
221 public:
bool operator<=(const
Time &_time) const;
226 public:
bool operator<=(
double _time) const;
231 public:
bool operator>(const struct timespec &_tv) const;
236 public:
bool operator>(const
Time &_time) const;
241 public:
bool operator>(
double _time) const;
246 public:
bool operator>=(const
Time &_time) const;
251 public:
bool operator>=(const struct timespec &_tv) const;
256 public:
bool operator>=(
double _time) const;
262 public: friend
std::ostream &operator<<(
std::ostream &_out,
265 _out << _time.sec <<
" " << _time.nsec;
277 _in.
setf(std::ios_base::skipws);
278 _in >> _time.
sec >> _time.
nsec;
289 private:
static Time wallTime;
293 private:
inline void Correct()
296 if (this->sec > 0 && this->nsec < 0)
298 int32_t n = abs(this->nsec / this->nsInSec) + 1;
300 this->nsec += n * this->nsInSec;
302 if (this->sec < 0 && this->nsec > 0)
304 int32_t n = abs(this->nsec / this->nsInSec) + 1;
306 this->nsec -= n * this->nsInSec;
310 this->sec += this->nsec / this->nsInSec;
311 this->nsec = this->nsec % this->nsInSec;
315 private:
static const int32_t nsInSec;
319 private:
static const int32_t nsInMs;
321 private:
static struct timespec clockResolution;
A Time class, can be used to hold wall- or sim-time. stored as sec and nano-sec.
Definition: gz/common/Time.hh:35
friend std::istream & operator>>(std::istream &_in, ignition::common::Time &_time)
Stream extraction operator.
Definition: gz/common/Time.hh:273
int32_t nsec
Nanoseconds.
Definition: gz/common/Time.hh:286
FormatOption
Definition: gz/common/Time.hh:42
int32_t sec
Seconds.
Definition: gz/common/Time.hh:283
static const Time Zero
A static zero time variable set to common::Time(0, 0).
Definition: gz/common/Time.hh:37
Forward declarations for the common classes.