Go to the documentation of this file.
17 #ifndef GZ_COMMON_TIME_HH_
18 #define GZ_COMMON_TIME_HH_
23 #include <gz/common/Export.hh>
33 class IGNITION_COMMON_VISIBLE
Time
63 public:
explicit Time(
const struct timespec &_tv);
68 public:
Time(int32_t _sec, int32_t _nsec);
72 public:
explicit Time(
double _time);
75 public:
virtual ~
Time();
79 public:
static const Time &SystemTime();
84 public:
void Set(int32_t _sec, int32_t _nsec);
88 public:
void Set(
double _seconds);
92 public:
double Double()
const;
96 public:
float Float()
const;
114 FormatOption _start = FormatOption::DAYS,
115 FormatOption _end = FormatOption::MILLISECONDS)
const;
120 public:
Time &operator=(
const Time &_time);
125 public:
Time operator+(
const Time &_time)
const;
130 public:
const Time &operator +=(
const Time &_time);
135 public:
Time operator -(
const struct timespec &_tv)
const;
140 public:
const Time &operator -=(
const struct timespec &_tv);
145 public:
Time operator -(
const Time &_time)
const;
150 public:
const Time &operator -=(
const Time &_time);
155 public:
Time operator *(
const struct timespec &_tv)
const;
160 public:
const Time &operator *=(
const struct timespec &_tv);
165 public:
Time operator *(
const Time &_time)
const;
170 public:
const Time &operator *=(
const Time &_time);
175 public:
const Time &operator /=(
const struct timespec &_tv);
180 public:
Time operator /(
const Time &_time)
const;
185 public:
const Time &operator /=(
const Time &time);
190 public:
bool operator==(
const Time &_time)
const;
195 public:
bool operator==(
double _time)
const;
200 public:
bool operator!=(
const Time &_time)
const;
205 public:
bool operator!=(
double _time)
const;
210 public:
bool operator<(
const Time &_time)
const;
215 public:
bool operator<(
double _time)
const;
220 public:
bool operator<=(
const Time &_time)
const;
225 public:
bool operator<=(
double _time)
const;
230 public:
bool operator>(
const struct timespec &_tv)
const;
235 public:
bool operator>(
const Time &_time)
const;
240 public:
bool operator>(
double _time)
const;
245 public:
bool operator>=(
const Time &_time)
const;
250 public:
bool operator>=(
const struct timespec &_tv)
const;
255 public:
bool operator>=(
double _time)
const;
264 _out << _time.
sec <<
" " << _time.
nsec;
276 _in.
setf(std::ios_base::skipws);
277 _in >> _time.
sec >> _time.
nsec;
288 private:
static Time wallTime;
292 private:
inline void Correct()
295 if (this->sec > 0 && this->nsec < 0)
297 int32_t n = abs(this->nsec / this->nsInSec) + 1;
299 this->nsec += n * this->nsInSec;
301 if (this->sec < 0 && this->nsec > 0)
303 int32_t n = abs(this->nsec / this->nsInSec) + 1;
305 this->nsec -= n * this->nsInSec;
309 this->sec += this->nsec / this->nsInSec;
310 this->nsec = this->nsec % this->nsInSec;
314 private:
static const int32_t nsInSec;
318 private:
static const int32_t nsInMs;
320 private:
static struct timespec clockResolution;
static const Time & SystemTime()
Get the wall time.
static Time Sleep(const common::Time &_time)
Sleep for the specified time.
bool operator<=(const Time &_time) const
Less than or equal to operator.
Forward declarations for the common classes.
Time operator-(const struct timespec &_tv) const
Subtraction operator.
A Time class, can be used to hold wall- or sim-time. stored as sec and nano-sec.
Definition: gz/common/Time.hh:33
bool operator==(const Time &_time) const
Equal to operator.
virtual ~Time()
Destructor.
bool operator>=(const Time &_time) const
Greater than or equal operator.
void Set(int32_t _sec, int32_t _nsec)
Set to sec and nsec.
Time operator*(const struct timespec &_tv) const
Multiplication operator.
bool operator<(const Time &_time) const
Less than operator.
int32_t nsec
Nanoseconds.
Definition: gz/common/Time.hh:285
const Time & operator*=(const struct timespec &_tv)
Multiplication assignment operator.
Time & operator=(const Time &_time)
Assignment operator.
std::string FormattedString(FormatOption _start=FormatOption::DAYS, FormatOption _end=FormatOption::MILLISECONDS) const
Get the time as a string formatted as "DD hh:mm:ss.mmm", with the option to choose the start/end.
friend std::istream & operator>>(std::istream &_in, ignition::common::Time &_time)
Stream extraction operator.
Definition: gz/common/Time.hh:272
@ MILLISECONDS
Milliseconds.
float Float() const
Get the time as a float.
friend std::ostream & operator<<(std::ostream &_out, const ignition::common::Time &_time)
Stream insertion operator.
Definition: gz/common/Time.hh:261
bool operator!=(const Time &_time) const
Equal to operator.
FormatOption
Definition: gz/common/Time.hh:40
const Time & operator+=(const Time &_time)
Addition assignemtn operator.
const Time & operator/=(const struct timespec &_tv)
Division assignment operator.
Time operator/(const Time &_time) const
Division operator.
Time operator+(const Time &_time) const
Addition operators.
bool operator>(const struct timespec &_tv) const
Greater than operator.
const Time & operator-=(const struct timespec &_tv)
Subtraction assignment operator.
double Double() const
Get the time as a double.
static const Time Zero
A static zero time variable set to common::Time(0, 0).
Definition: gz/common/Time.hh:36
int32_t sec
Seconds.
Definition: gz/common/Time.hh:282