2018-07-21 22:57:21 +08:00
|
|
|
#include "..\e2dcommon.h"
|
|
|
|
|
|
|
|
|
|
using namespace std::chrono;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
e2d::Time::Time()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-22 00:41:24 +08:00
|
|
|
time_t e2d::Time::getTimeStamp() const
|
2018-07-21 22:57:21 +08:00
|
|
|
{
|
2018-07-29 01:43:15 +08:00
|
|
|
auto& duration = time_point_cast<milliseconds>(_timePoint).time_since_epoch();
|
|
|
|
|
return static_cast<time_t>(duration.count());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool e2d::Time::isZero() const
|
|
|
|
|
{
|
|
|
|
|
return _timePoint.time_since_epoch().count() == 0LL;
|
2018-07-21 22:57:21 +08:00
|
|
|
}
|
|
|
|
|
|
2018-07-22 00:41:24 +08:00
|
|
|
e2d::Time e2d::Time::operator+(Duration const & other) const
|
2018-07-21 22:57:21 +08:00
|
|
|
{
|
2018-08-02 00:27:45 +08:00
|
|
|
Time t;
|
|
|
|
|
t._timePoint = _timePoint + milliseconds(other.milliseconds());
|
|
|
|
|
return std::move(t);
|
2018-07-22 21:22:27 +08:00
|
|
|
}
|
|
|
|
|
|
2018-08-02 00:27:45 +08:00
|
|
|
e2d::Time e2d::Time::operator-(Duration const & other) const
|
2018-07-22 21:22:27 +08:00
|
|
|
{
|
2018-08-02 00:27:45 +08:00
|
|
|
Time t;
|
|
|
|
|
t._timePoint = _timePoint - milliseconds(other.milliseconds());
|
|
|
|
|
return std::move(t);
|
2018-07-22 00:41:24 +08:00
|
|
|
}
|
|
|
|
|
|
2018-08-02 00:27:45 +08:00
|
|
|
e2d::Time & e2d::Time::operator+=(Duration const & other)
|
2018-07-29 01:43:15 +08:00
|
|
|
{
|
2018-08-02 00:27:45 +08:00
|
|
|
_timePoint += milliseconds(other.milliseconds());
|
|
|
|
|
return (*this);
|
2018-07-29 01:43:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
e2d::Time & e2d::Time::operator-=(Duration const &other)
|
|
|
|
|
{
|
|
|
|
|
_timePoint -= milliseconds(other.milliseconds());
|
|
|
|
|
return (*this);
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-22 00:41:24 +08:00
|
|
|
e2d::Duration e2d::Time::operator-(Time const & other) const
|
|
|
|
|
{
|
2018-08-02 00:27:45 +08:00
|
|
|
auto ms = duration_cast<milliseconds>(_timePoint - other._timePoint).count();
|
|
|
|
|
return std::move(Duration(static_cast<float>(ms) / 1000.f));
|
2018-07-22 00:41:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
e2d::Time e2d::Time::now()
|
|
|
|
|
{
|
2018-08-02 00:27:45 +08:00
|
|
|
Time t;
|
|
|
|
|
t._timePoint = steady_clock::now();
|
|
|
|
|
return std::move(t);
|
2018-07-21 22:57:21 +08:00
|
|
|
}
|