22#include <kiwano/core/Common.h>
60 int64_t GetMilliseconds()
const;
64 float GetSeconds()
const;
68 float GetMinutes()
const;
72 float GetHours()
const;
82 void SetMilliseconds(int64_t ms);
87 void SetSeconds(
float seconds);
92 void SetMinutes(
float minutes);
97 void SetHours(
float hours);
105 String ToString()
const;
118 bool operator==(
const Duration&)
const;
119 bool operator!=(
const Duration&)
const;
120 bool operator>(
const Duration&)
const;
121 bool operator>=(
const Duration&)
const;
122 bool operator<(
const Duration&)
const;
123 bool operator<=(
const Duration&)
const;
125 float operator/(
const Duration&)
const;
130 const Duration operator*(
int)
const;
131 const Duration operator*(
unsigned long long)
const;
132 const Duration operator*(
float)
const;
133 const Duration operator*(
double)
const;
134 const Duration operator*(
long double)
const;
135 const Duration operator/(
int)
const;
136 const Duration operator/(
float)
const;
137 const Duration operator/(
double)
const;
157 int64_t milliseconds_;
176 : milliseconds_(milliseconds)
182 return milliseconds_;
187 return milliseconds_ == 0LL;
197 milliseconds_ =
static_cast<int64_t
>(seconds * 1000.f);
202 milliseconds_ =
static_cast<int64_t
>(minutes * 60 * 1000.f);
207 milliseconds_ =
static_cast<int64_t
>(hours * 60 * 60 * 1000.f);
210inline bool Duration::operator==(
const Duration& other)
const
212 return milliseconds_ == other.milliseconds_;
215inline bool Duration::operator!=(
const Duration& other)
const
217 return milliseconds_ != other.milliseconds_;
220inline bool Duration::operator>(
const Duration& other)
const
222 return milliseconds_ > other.milliseconds_;
225inline bool Duration::operator>=(
const Duration& other)
const
227 return milliseconds_ >= other.milliseconds_;
230inline bool Duration::operator<(
const Duration& other)
const
232 return milliseconds_ < other.milliseconds_;
235inline bool Duration::operator<=(
const Duration& other)
const
237 return milliseconds_ <= other.milliseconds_;
240inline float Duration::operator/(
const Duration& other)
const
242 return static_cast<float>(milliseconds_) / other.milliseconds_;
245inline const Duration Duration::operator+(
const Duration& other)
const
247 return Duration(milliseconds_ + other.milliseconds_);
250inline const Duration Duration::operator-(
const Duration& other)
const
252 return Duration(milliseconds_ - other.milliseconds_);
255inline const Duration Duration::operator-()
const
260inline const Duration Duration::operator*(
int val)
const
262 return Duration(milliseconds_ * val);
265inline const Duration Duration::operator*(
unsigned long long val)
const
267 return Duration(
static_cast<int64_t
>(milliseconds_ * val));
270inline const Duration Duration::operator*(
float val)
const
272 return Duration(
static_cast<int64_t
>(milliseconds_ * val));
275inline const Duration Duration::operator*(
double val)
const
277 return Duration(
static_cast<int64_t
>(milliseconds_ * val));
280inline const Duration Duration::operator*(
long double val)
const
282 return Duration(
static_cast<int64_t
>(milliseconds_ * val));
285inline const Duration Duration::operator/(
int val)
const
287 return Duration(milliseconds_ / val);
290inline const Duration Duration::operator/(
float val)
const
292 return Duration(
static_cast<int64_t
>(milliseconds_ / val));
295inline const Duration Duration::operator/(
double val)
const
297 return Duration(
static_cast<int64_t
>(milliseconds_ / val));
300inline Duration& Duration::operator+=(
const Duration& other)
302 milliseconds_ += other.milliseconds_;
306inline Duration& Duration::operator-=(
const Duration& other)
308 milliseconds_ -= other.milliseconds_;
312inline Duration& Duration::operator*=(
int val)
314 milliseconds_ *= val;
318inline Duration& Duration::operator/=(
int val)
320 milliseconds_ =
static_cast<int64_t
>(milliseconds_ / val);
324inline Duration& Duration::operator*=(
float val)
326 milliseconds_ =
static_cast<int64_t
>(milliseconds_ * val);
330inline Duration& Duration::operator/=(
float val)
332 milliseconds_ =
static_cast<int64_t
>(milliseconds_ / val);
336inline Duration& Duration::operator*=(
double val)
338 milliseconds_ =
static_cast<int64_t
>(milliseconds_ * val);
342inline Duration& Duration::operator/=(
double val)
344 milliseconds_ =
static_cast<int64_t
>(milliseconds_ / val);
348inline const Duration operator*(
int val,
const Duration& dur)
353inline const Duration operator/(
int val,
const Duration& dur)
358inline const Duration operator*(
float val,
const Duration& dur)
363inline const Duration operator/(
float val,
const Duration& dur)
368inline const Duration operator*(
double val,
const Duration& dur)
373inline const Duration operator/(
double val,
const Duration& dur)
378inline const Duration operator*(
long double val,
const Duration& dur)
385#if defined(KGE_HAS_LITERALS)
389inline namespace literals
393 return kiwano::time::Millisecond * val;
398 return kiwano::time::Millisecond * val;
403 return kiwano::time::Second * val;
408 return kiwano::time::Second * val;
413 return kiwano::time::Minute * val;
418 return kiwano::time::Minute * val;
423 return kiwano::time::Hour * val;
428 return kiwano::time::Hour * val;
时间段
Definition: Duration.h:48
void SetMilliseconds(int64_t ms)
设置毫秒数
Definition: Duration.h:190
void SetSeconds(float seconds)
设置秒数
Definition: Duration.h:195
bool IsZero() const
时长是否是零
Definition: Duration.h:185
Duration()
构造时间段
Definition: Duration.h:170
void SetMinutes(float minutes)
设置分钟数
Definition: Duration.h:200
void SetHours(float hours)
设置小时数
Definition: Duration.h:205
int64_t GetMilliseconds() const
获取毫秒数
Definition: Duration.h:180